idlast.cc
来自「编译工具」· CC 代码 · 共 2,492 行 · 第 1/5 页
CC
2,492 行
InheritSpec::InheritSpec(const ScopedName* sn, const char* file, int line) : interface_(0), decl_(0), scope_(0), next_(0){ const Scope::Entry* se = Scope::current()->findScopedName(sn, file, line); if (se) { if (se->kind() == Scope::Entry::E_DECL) { decl_ = se->decl(); IdlType* t = se->idltype()->unalias(); if (!t) return; if (t->kind() == IdlType::tk_objref || t->kind() == IdlType::tk_abstract_interface || t->kind() == IdlType::tk_local_interface) { Decl* d = ((DeclaredType*)t)->decl(); if (!d) { char* ssn = sn->toString(); IdlError(file, line, "Cannot inherit from CORBA::Object"); IdlErrorCont(se->file(), se->line(), "(accessed through typedef '%s')", ssn); delete [] ssn; return; } else if (d->kind() == Decl::D_INTERFACE) { interface_ = (Interface*)d; scope_ = interface_->scope(); return; } else if (d->kind() == Decl::D_FORWARD) { Interface* def = ((Forward*)d)->definition(); if (def) { interface_ = def; scope_ = interface_->scope(); return; } else { char* ssn = ((Forward*)d)->scopedName()->toString(); IdlError(file, line, "Inherited interface '%s' must be fully defined", ssn); if (decl_ != d) { char* tssn = sn->toString(); IdlErrorCont(se->file(), se->line(), "('%s' reached through typedef '%s')", ssn, tssn); delete [] tssn; } IdlErrorCont(d->file(), d->line(), "('%s' forward declared here)", ssn); delete [] ssn; return; } } } } char* ssn = sn->toString(); IdlError(file, line, "'%s' used in inheritance specification is not an interface", ssn); IdlErrorCont(se->file(), se->line(), "('%s' declared here)", ssn); delete [] ssn; }}voidInheritSpec::append(InheritSpec* is, const char* file, int line){ InheritSpec *i, *last; if (is->interface()) { for (i=this; i; i = i->next_) { last = i; if (is->interface() == i->interface()) { char* ssn = is->interface()->scopedName()->toString(); IdlError(file, line, "Cannot specify '%s' as a direct base interface " "more than once", ssn); delete [] ssn; delete is; return; } } last->next_ = is; }}Interface::Interface(const char* file, int line, IDL_Boolean mainFile, const char* identifier, IDL_Boolean abstract, IDL_Boolean local, InheritSpec* inherits) : Decl(D_INTERFACE, file, line, mainFile), DeclRepoId(identifier), abstract_(abstract), local_(local), inherits_(inherits), contents_(0){ // Look for forward interface Scope::Entry* se = Scope::current()->find(identifier); if (se && se->kind() == Scope::Entry::E_DECL && se->decl() && se->decl()->kind() == Decl::D_FORWARD) { Forward* f = (Forward*)se->decl(); if (strcmp(f->prefix(), prefix())) { IdlError(file, line, "In declaration of interface '%s', repository id " "prefix '%s' differs from that of forward declaration", identifier, prefix()); IdlErrorCont(f->file(), f->line(), "('%s' forward declared here with prefix '%s')", f->identifier(), f->prefix()); } if (abstract && !f->abstract()) { IdlError(file, line, "Declaration of abstract interface '%s' conflicts with " "forward declaration as non-abstract", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as non-abstract here)"); } else if (!abstract && f->abstract()) { IdlError(file, line, "Declaration of non-abstract interface '%s' conflicts with " "forward declaration as abstract", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as abstract here)"); } if (local && !f->local()) { IdlError(file, line, "Declaration of local interface '%s' conflicts with " "forward declaration as unconstrained", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as unconstrained here)"); } else if (!local && f->local()) { IdlError(file, line, "Declaration of unconstrained interface '%s' conflicts with " "forward declaration as local", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as local here)"); } if (f->repoIdSet()) setRepoId(f->repoId(), f->rifile(), f->riline()); f->setDefinition(this); Scope::current()->remEntry(se); } scope_ = Scope::current()->newInterfaceScope(identifier, file, line); if (abstract_) { thisType_ = new DeclaredType(IdlType::tk_abstract_interface, this, this); // Check that all inherited interfaces are abstract for (InheritSpec* inh = inherits; inh; inh = inh->next()) { if (!inh->interface()->abstract()) { char* ssn = inh->scope()->scopedName()->toString(); IdlError(file, line, "In declaration of abstract interface '%s', inherited " "interface '%s' is not abstract", identifier, ssn); IdlErrorCont(inh->interface()->file(), inh->interface()->line(), "(%s declared here)", ssn); delete [] ssn; } } } else if (local_) { thisType_ = new DeclaredType(IdlType::tk_local_interface, this, this); thisType_->setLocal(); } else { thisType_ = new DeclaredType(IdlType::tk_objref, this, this); // Check that all inherited interfaces are unconstrained for (InheritSpec* inh = inherits; inh; inh = inh->next()) { if (inh->interface() && inh->interface()->local()) { char* ssn = inh->scope()->scopedName()->toString(); IdlError(file, line, "In declaration of unconstrained interface '%s', inherited " "interface '%s' is local", identifier, ssn); IdlErrorCont(inh->interface()->file(), inh->interface()->line(), "(%s declared here)", ssn); delete [] ssn; } } } scope_->setInherited(inherits, file, line); Scope::current()->addDecl(identifier, scope_, this, thisType_, file, line); Scope::startScope(scope_); Prefix::newScope(identifier);}Interface::~Interface(){ if (inherits_) delete inherits_; if (contents_) delete contents_; delete thisType_;}voidInterface::finishConstruction(Decl* decls){ contents_ = decls; Prefix::endScope(); Scope::endScope(); mostRecent_ = this; if (!local_) { for (Decl* d = decls; d; d = d->next()) { if (d->kind() == D_ATTRIBUTE) { Attribute* a = (Attribute*)d; if (a->attrType() && a->attrType()->local()) { DeclaredType* dt = (DeclaredType*)a->attrType(); assert(dt->declRepoId()); char* ssn = dt->declRepoId()->scopedName()->toString(); IdlError(a->file(), a->line(), "In unconstrained interface '%s', attribute '%s' has " "local type '%s'", identifier(), a->declarators()->identifier(), ssn); IdlErrorCont(dt->decl()->file(), dt->decl()->line(), "(%s declared here)", ssn); delete [] ssn; } } else if (d->kind() == D_OPERATION) { Operation* o = (Operation*)d; if (o->returnType() && o->returnType()->local()) { DeclaredType* dt = (DeclaredType*)o->returnType(); assert(dt->declRepoId()); char* ssn = dt->declRepoId()->scopedName()->toString(); IdlError(o->file(), o->line(), "In unconstrained interface '%s', operation '%s' has " "local return type '%s'", identifier(), o->identifier(), ssn); IdlErrorCont(dt->decl()->file(), dt->decl()->line(), "(%s declared here)", ssn); delete [] ssn; } for (Parameter* p = o->parameters(); p; p = (Parameter*)p->next()) { if (p->paramType() && p->paramType()->local()) { DeclaredType* dt = (DeclaredType*)p->paramType(); assert(dt->declRepoId()); char* ssn = dt->declRepoId()->scopedName()->toString(); IdlError(p->file(), p->line(), "In unconstrained interface '%s', operation '%s' has " "parameter '%s' with local type '%s'", identifier(), o->identifier(), p->identifier(), ssn); IdlErrorCont(dt->decl()->file(), dt->decl()->line(), "(%s declared here)", ssn); delete [] ssn; } } for (RaisesSpec* r = o->raises(); r; r = r->next()) { if (r->exception() && r->exception()->local()) { char* ssn = r->exception()->scopedName()->toString(); IdlError(o->file(), o->line(), "In unconstrained interface '%s', operation '%s' raises " "local exception '%s'", identifier(), o->identifier(), ssn); IdlErrorCont(r->exception()->file(), r->exception()->line(), "(%s declared here)", ssn); delete [] ssn; } } } } }}// ForwardForward::Forward(const char* file, int line, IDL_Boolean mainFile, const char* identifier, IDL_Boolean abstract, IDL_Boolean local) : Decl(D_FORWARD, file, line, mainFile), DeclRepoId(identifier), abstract_(abstract), local_(local), definition_(0), firstForward_(0), thisType_(0){ Scope::Entry* se = Scope::current()->find(identifier); IDL_Boolean reg = 1; if (se && se->kind() == Scope::Entry::E_DECL) { if (se->decl()->kind() == D_INTERFACE) { Interface* i = (Interface*)se->decl(); definition_ = i; if (strcmp(i->prefix(), prefix())) { IdlError(file, line, "In forward declaration of interface '%s', repository " "id prefix '%s' differs from that of earlier declaration", identifier, prefix()); IdlErrorCont(i->file(), i->line(), "('%s' fully declared here with prefix '%s')", i->identifier(), i->prefix()); } if (abstract && !i->abstract()) { IdlError(file, line, "Forward declaration of abstract interface '%s' conflicts " "with earlier full declaration as non-abstract", identifier); IdlErrorCont(i->file(), i->line(), "('%s' declared as non-abstract here)"); } else if (!abstract && i->abstract()) { IdlError(file, line, "Forward declaration of non-abstract interface '%s' " "conflicts with earlier full declaration as abstract", identifier); IdlErrorCont(i->file(), i->line(), "('%s' declared as abstract here)"); } if (local && !i->local()) { IdlError(file, line, "Forward declaration of local interface '%s' conflicts " "with earlier full declaration as unconstrained", identifier); IdlErrorCont(i->file(), i->line(), "('%s' declared as unconstrained here)"); } else if (!local && i->local()) { IdlError(file, line, "Forward declaration of unconstrained interface '%s' " "conflicts with earlier full declaration as local", identifier); IdlErrorCont(i->file(), i->line(), "('%s' declared as abstract here)"); } reg = 0; } else if (se->decl()->kind() == D_FORWARD) { Forward* f = (Forward*)se->decl(); firstForward_ = f; if (strcmp(f->prefix(), prefix())) { IdlError(file, line, "In forward declaration of interface '%s', repository " "id prefix '%s' differs from that of earlier declaration", identifier, prefix()); IdlErrorCont(f->file(), f->line(), "('%s' forward declared here with prefix '%s')", f->identifier(), f->prefix()); } if (abstract && !f->abstract()) { IdlError(file, line, "Forward declaration of abstract interface '%s' conflicts " "with earlier forward declaration as non-abstract", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as non-abstract here)"); } else if (!abstract && f->abstract()) { IdlError(file, line, "Forward declaration of non-abstract interface '%s' " "conflicts with earlier forward declaration as abstract", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as abstract here)"); } if (local && !f->local()) { IdlError(file, line, "Forward declaration of local interface '%s' conflicts " "with earlier forward declaration as unconstrained", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as unconstrained here)"); } else if (!local && f->local()) { IdlError(file, line, "Forward declaration of unconstrained interface '%s' " "conflicts with earlier forward declaration as local", identifier); IdlErrorCont(f->file(), f->line(), "('%s' forward declared as local here)"); } //***? if (f->repoIdSet()) setRepoId(f->repoId(), f->rifile(), f->riline()); reg = 0; } } if (reg) { if (abstract) { thisType_ = new DeclaredType(IdlType::tk_abstract_interface, this, this); } else if (local) { thisType_ = new DeclaredType(IdlType::tk_local_interface, this, this); thisType_->setLocal(); } else { thisType_ = new DeclaredType(IdlType::tk_objref, this, this); } Scope::current()->addDecl(identifier, 0, this, thisType_, file, line); }}Forward::~Forward(){ delete thisType_;}Interface*Forward::definition() const{ if (firstForward_) return firstForward_->definition(); else return definition_;}voidForward::setDefinition(Interface* defn){ definition_ = defn;}// ConstConst::Const(const char* file, int line, IDL_Boolean mainFile, IdlType* constType, const char* identifier, IdlExpr* expr) : Decl(D_CONST, file, line, mainFile), DeclRepoId(identifier), constType_(constType){ if (constType) delType_ = constType->shouldDelete(); else delType_ = 0; if (!constType || !expr) return; // Ignore nulls due to earlier errors IdlType* t = constType->unalias(); if (!t) { // Broken alias due to earlier error constKind_ = IdlType::tk_null; delete expr; return; } constKind_ = t->kind(); switch (constKind_) { case IdlType::tk_short: v_.short_ = expr->evalAsShort(); break; case IdlType::tk_long: v_.long_ = expr->evalAsLong(); break; case IdlType::tk_ushort: v_.ushort_ = expr->evalAsUShort(); break; case IdlType::tk_ulong: v_.ulong_ = expr->evalAsULong(); break; case IdlType::tk_float: v_.float_ = expr->evalAsFloat(); break; case IdlType::tk_double: v_.double_ = expr->evalAsDouble(); break; case IdlType::tk_boolean: v_.boolean_ = expr->evalAsBoolean(); break; case IdlType::tk_char: v_.char_ = expr->evalAsChar(); break; case IdlType::tk_octet: v_.octet_ = expr->evalAsOctet(); break; case IdlType::tk_string: { v_.string_ = idl_strdup(expr->evalAsString()); IDL_ULong bound = ((StringType*)t)->bound(); if (bound && strlen(v_.string_) > bound) { IdlError(file, line, "Length of bounded string constant exceeds bound"); } break; }#ifdef HAS_LongLong case IdlType::tk_longlong: v_.longlong_ = expr->evalAsLongLong(); break; case IdlType::tk_ulonglong: v_.ulonglong_ = expr->evalAsULongLong(); break;#endif#ifdef HAS_LongDouble case IdlType::tk_longdouble: v_.longdouble_ = expr->evalAsLongDouble();break;#endif case IdlType::tk_wchar: v_.wchar_ = expr->evalAsWChar(); break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?