idlscope.cc
来自「编译工具」· CC 代码 · 共 1,370 行 · 第 1/3 页
CC
1,370 行
// -*- c++ -*-// Package : omniidl// idlscope.cc Created on: 1999/10/11// Author : Duncan Grisby (dpg1)//// Copyright (C) 1999 AT&T Laboratories Cambridge//// This file is part of omniidl.//// omniidl is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA// 02111-1307, USA.//// Description:// // Scope manipulation// $Id: idlscope.cc,v 1.13.2.10 2005/05/03 10:12:34 dgrisby Exp $// $Log: idlscope.cc,v $// Revision 1.13.2.10 2005/05/03 10:12:34 dgrisby// Trying to redefine built in CORBA module types led to a segfault.//// Revision 1.13.2.9 2003/04/09 10:26:48 dgrisby// Silly variable reuse bug in new CORBA 3 keyword check.//// Revision 1.13.2.8 2003/03/20 10:24:27 dgrisby// Warn about use of CORBA 3 keywords in IDL.//// Revision 1.13.2.7 2001/10/29 17:42:43 dpg1// Support forward-declared structs/unions, ORB::create_recursive_tc().//// Revision 1.13.2.6 2001/10/17 16:48:33 dpg1// Minor error message tweaks//// Revision 1.13.2.5 2001/06/08 17:12:23 dpg1// Merge all the bug fixes from omni3_develop.//// Revision 1.13.2.4 2000/12/05 17:45:19 dpg1// omniidl case sensitivity updates from omni3_develop.//// Revision 1.13.2.3 2000/10/27 16:31:10 dpg1// Clean up of omniidl dependencies and types, from omni3_develop.//// Revision 1.13.2.2 2000/10/10 10:18:51 dpg1// Update omniidl front-end from omni3_develop.//// Revision 1.11.2.6 2000/09/19 09:14:26 dpg1// Scope::Entry::Kind renamed to Scope::Entry::EntryKind to avoid// problems with over-keen compilers//// Revision 1.11.2.5 2000/08/29 15:20:28 dpg1// New relativeScope() function. New -i flag to enter interactive loop// after parsing//// Revision 1.11.2.4 2000/08/24 11:33:00 dpg1// Typo in error message % format string//// Revision 1.11.2.3 2000/08/04 09:10:27 dpg1// Fix look-up of escaped identifiers broken on 19 July. (Bug 14.)//// Revision 1.11.2.2 2000/08/01 09:46:47 dpg1// No longer complain about inheriting an operation into an interface// with the same name.//// Revision 1.11.2.1 2000/07/19 17:24:54 dpg1// omniidl complains if a name which differs only in case is found during// name look-up//// Revision 1.11 1999/11/26 11:33:44 dpg1// Bug in findWithInheritance() when inherited interface was not found.//// Revision 1.10 1999/11/17 17:23:54 dpg1// Minor bug when scoped name look-up encounters an identifier which does// not form a scope.//// Revision 1.9 1999/11/17 17:17:00 dpg1// Changes to remove static initialisation of objects.//// Revision 1.8 1999/11/11 10:20:30 dpg1// Bug in marking use of fully-scoped names.//// Revision 1.7 1999/11/04 17:16:55 dpg1// Changes for NT.//// Revision 1.6 1999/11/02 17:07:25 dpg1// Changes to compile on Solaris.//// Revision 1.5 1999/11/02 12:10:51 dpg1// Small bug in addUse()//// Revision 1.4 1999/11/02 10:35:03 dpg1// add...() functions now carry on regardless after a keyword clash, to// prevent later errors.//// Revision 1.3 1999/11/02 10:01:46 dpg1// Minor fixes.//// Revision 1.2 1999/10/29 10:01:50 dpg1// Global scope initialisation changed.//// Revision 1.1 1999/10/27 14:05:55 dpg1// *** empty log message ***//#include <idlscope.h>#include <idlast.h>#include <idlerr.h>#include <idlutil.h>#include <idlconfig.h>#include <idlrepoId.h>#include <string.h>// Global Scope pointersScope* Scope::global_ = 0;Scope* Scope::current_ = 0;int n_builtins = 0;static Decl** builtins = 0;// ScopedName implementationScopedName::ScopedName(const char* identifier, IDL_Boolean absolute) : absolute_(absolute){ Fragment* f = new Fragment(identifier); scopeList_ = f; last_ = f;}ScopedName::ScopedName(const ScopedName* sn) : scopeList_(0), last_(0), absolute_(sn->absolute()){ const Fragment *f; for (f = sn->scopeList(); f; f = f->next()) append(f->identifier());}ScopedName::ScopedName(const ScopedName::Fragment* frags, IDL_Boolean absolute) : scopeList_(0), last_(0), absolute_(absolute){ const Fragment *f; for (f = frags; f; f = f->next()) append(f->identifier());}ScopedName::~ScopedName(){ Fragment* f; Fragment* g; for (f = scopeList_; f; f = g) { g = f->next_; delete f; }}char*ScopedName::toString(IDL_Boolean qualify) const{ int i; Fragment* f; i = (qualify && absolute_) ? 2 : 0; for (f = scopeList_; f; f = f->next()) i += strlen(f->identifier()) + 2; char* str = new char [i-1]; if (qualify && absolute_) { str[0] = ':'; str[1] = ':'; i = 2; } else i = 0; const char* fi; for (f = scopeList_; f; f = f->next()) { for (fi = f->identifier(); *fi; fi++, i++) str[i] = *fi; if (f->next()) { str[i++] = ':'; str[i++] = ':'; } } str[i] = '\0'; return str;}IDL_BooleanScopedName::equal(const ScopedName* sn) const{ if (sn->absolute() != absolute()) return 0; Fragment *ourf, *theirf; // Compare fragments for (ourf = scopeList(), theirf = sn->scopeList(); ourf && theirf; ourf = ourf->next(), theirf = theirf->next()) { if (strcmp(ourf->identifier(), theirf->identifier()) != 0) return 0; } // If either name has fragments left, names aren't equal if (ourf || theirf) return 0; return 1;}voidScopedName::append(const char* identifier){ Fragment* f = new Fragment(identifier); if (last_) last_->next_ = f; else scopeList_ = f; last_ = f;}// Scope implementationScope::Entry::Entry(const Scope* container, EntryKind k, const char* identifier, Scope* scope, Decl* decl, IdlType* idltype, Scope::Entry* inh_from, const char* file, int line) : container_(container), kind_(k), identifier_(idl_strdup(identifier)), scope_(scope), decl_(decl), idltype_(idltype), inh_from_(inh_from), file_(idl_strdup(file)), line_(line), next_(0){ const ScopedName* sn = container->scopedName(); if (identifier) { if (sn) { scopedName_ = new ScopedName(sn); scopedName_->append(identifier); } else scopedName_ = new ScopedName(identifier, 1); } else scopedName_ = 0;}Scope::Entry::~Entry(){ if (scopedName_) delete scopedName_; if (identifier_) delete [] identifier_; if (file_) delete [] file_;}voidScope::EntryList::merge(Scope::EntryList* ml){ EntryList* l; IDL_Boolean add; for (; ml; ml = ml->tail()) { add = 1; for (l=this; l; l = l->tail()) { if (ml->head() == l->head()) { add = 0; break; } } if (add) append(new EntryList(ml->head())); } delete ml;}Scope::Scope(Scope* parent, Scope::Kind k, IDL_Boolean nestedUse, const char* file, int line) : parent_(parent), kind_(k), identifier_(0), scopedName_(0), nestedUse_(nestedUse), entries_(0), last_(0), inherited_(0), valueInherited_(0){ if (parent) nestedUse_ |= parent->nestedUse();}Scope::Scope(Scope* parent, const char* identifier, Scope::Kind k, IDL_Boolean nestedUse, const char* file, int line) : parent_(parent), kind_(k), nestedUse_(nestedUse), inherited_(0), valueInherited_(0){ const ScopedName* psn = 0; if (identifier && identifier[0] == '_') ++identifier; identifier_ = idl_strdup(identifier); if (parent) { psn = parent->scopedName(); nestedUse_ |= parent->nestedUse(); } if (psn) { scopedName_ = new ScopedName(psn); scopedName_->append(identifier); } else scopedName_ = new ScopedName(identifier, 1); // Add PARENT entry entries_ = new Entry(this, Entry::E_PARENT, identifier, 0, 0, 0, 0, file, line); last_ = entries_;}Scope::~Scope(){ Entry *e, *f; for (e=entries_; e; e=f) { f = e->next(); delete e; } if (identifier_) delete [] identifier_; if (scopedName_) delete scopedName_;}voidScope::init(){ const char* file = "<built in>"; assert(global_ == 0); Prefix::newFile(); global_ = new Scope(0, Scope::S_GLOBAL, 0, file, 0); Scope* s = global_->newModuleScope("CORBA", file, 1); global_->addModule("CORBA", s, 0, file, 1); current_ = global_; n_builtins = 2; assert (builtins == 0); builtins = new Decl*[n_builtins]; builtins[0] = new Native(file, 2, 0, "TypeCode"); builtins[1] = new Native(file, 3, 0, "Principal"); s->addDecl("TypeCode", 0, builtins[0], BaseType::TypeCodeType, file, 2); s->addDecl("Principal", 0, builtins[1], BaseType::PrincipalType, file, 3); Prefix::endOuterFile();}voidScope::clear(){ assert(global_ != 0); delete global_; global_ = 0; for (int i=0; i < n_builtins; i++) delete builtins[i]; delete [] builtins; builtins = 0;}voidScope::setInherited(InheritSpec* inherited, const char* file, int line){ inherited_ = inherited; InheritSpec* is; Entry* e; for (is = inherited; is; is = is->next()) { if (!is->scope()) continue; // Skip bad entries from earlier errors for (e = is->scope()->entries(); e; e = e->next()) { switch (e->kind()) { case Entry::E_CALLABLE: addInherited(e->identifier(), e->scope(), e->decl(), e, file, line); break; case Entry::E_INHERITED: addInherited(e->identifier(), e->scope(), e->decl(), e->inh_from(), file, line); break; default: break; } } }}voidScope::setInherited(ValueInheritSpec* inherited, const char* file, int line){ valueInherited_ = inherited; ValueInheritSpec* is; Entry* e; for (is = inherited; is; is = is->next()) { if (!is->scope()) continue; // Skip bad entries from earlier errors for (e = is->scope()->entries(); e; e = e->next()) { switch (e->kind()) { case Entry::E_CALLABLE: case Entry::E_INHERITED: addInherited(e->identifier(), e->scope(), e->decl(), e, file, line); break; default: break; } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?