示例#1
0
string Jce2Php::readFrom(const TypeIdPtr &pPtr, bool bIsRequire) const
{
    ostringstream s;
    s<<TAB<<"$this->"<<pPtr->getId()<<"->read($_in ";
    s << ", " << pPtr->getTag() << ", " << ((pPtr->isRequire() && bIsRequire)?"true":"false") << ");" << endl;
    return s.str();
}
示例#2
0
void Enum::addMember(const TypeIdPtr &typeIdPtr)
{
    for(size_t i = 0; i < _members.size(); i++)
    {
        if(_members[i]->getId() == typeIdPtr->getId())
        {
            g_parse->error("enum member '" + typeIdPtr->getId() + "' duplicate definition");
        }
    }
    _members.push_back(typeIdPtr);
}
示例#3
0
ConstPtr Namespace::createConst(TypeIdPtr &pPtr, ConstGrammarPtr &cPtr)
{
    for(size_t i = 0; i < _cs.size(); i++)
    {
        if(_cs[i]->getTypeIdPtr()->getId() == pPtr->getId())
        {
            g_parse->error("const type '" + pPtr->getId() + "' exists in namespace '" + _id + "'");
            return NULL;
        }
    }

    g_parse->checkConstValue(pPtr, cPtr->t);
    _cs.push_back(new Const(pPtr, cPtr));

    return _cs.back();
}
示例#4
0
/*******************************获取定长数组坐标********************************/
int Jce2Php::getSuffix(const TypeIdPtr &pPtr) const
{
    BuiltinPtr bPtr = BuiltinPtr::dynamicCast(pPtr->getTypePtr());
    if(bPtr && bPtr->kind() == Builtin::KindString && bPtr->isArray())
    {
        return bPtr->getSize();
    }

    VectorPtr vPtr = VectorPtr::dynamicCast(pPtr->getTypePtr());
    if(vPtr && vPtr->isArray())
    {
        return vPtr->getSize();
    }

    return -1;
}
示例#5
0
ParamDeclPtr Operation::createParamDecl(const TypeIdPtr &typeIdPtr, bool v, bool k)
{
    _itag++;
    if(_itag > 255)
    {
        g_parse->error("operation '" + _id + "' can't have more than 255 paramters!");
    }

    if(typeIdPtr->getId() == getId())
    {
        g_parse->error("paramters name '" + _id + "' conflicts with operation name!");
    }

    typeIdPtr->setRequire(_itag);
    _ps.push_back(new ParamDecl(typeIdPtr, v, k));
    return _ps.back();
}
示例#6
0
void Struct::addTypeId(const TypeIdPtr &typeIdPtr)
{
    StructPtr sp = StructPtr::dynamicCast(typeIdPtr->getTypePtr());
    if(sp)
    {
        if(sp->getSid() == getSid())
        {
            g_parse->error("struct can't take self as member data");
        }
    }

    for(size_t i = 0; i < _members.size(); i++)
    {
        if(_members[i]->getId() == typeIdPtr->getId())
        {
            g_parse->error("data member '" + typeIdPtr->getId() + "' duplicate definition");
        }
        if(_members[i]->getTag() == typeIdPtr->getTag())
        {
            g_parse->error("data member '" + typeIdPtr->getId() + "' has equal tag with '" + _members[i]->getId() + "'");
        }

        if(_members[i]->getTag() > typeIdPtr->getTag())
        {
            _members.insert(_members.begin() + i, typeIdPtr);
            return;
        }
    }

    _members.push_back(typeIdPtr);
}
示例#7
0
文件: parse.cpp 项目: daliniu/mobile
void HceParse::checkConstValue(TypeIdPtr &tPtr, int c)
{
    //只有内建类型才能有缺省值
    BuiltinPtr bPtr  = BuiltinPtr::dynamicCast(tPtr->getTypePtr());
    if(!bPtr)
    {
        error("only base type can have default value");
    }

    int b = bPtr->kind();

    if(c == ConstTok::VALUE)
    {
        if(b == Builtin::KindBool)
        {
            error("default value of bool can only be true or false");
        }
        if(b == Builtin::KindString)
        {
            error("default value of string can only be \"string\"");
        }
    }
    else if(c == ConstTok::BOOL)
    {
        if(b != Builtin::KindBool)
        {
            error("only bool type can be true or false");
        }
    }
    else if(c == ConstTok::STRING)
    {
        if(b != Builtin::KindString)
        {
            error("only string type can be \"string\"");
        }
    }
}
示例#8
0
string Jce2Php::writeTo(const TypeIdPtr &pPtr) const
{
    ostringstream s;
    s << TAB << "$this->" << pPtr->getId() << "->write($_out," << pPtr->getTag() << ");" << endl;
    return s.str();
}