idlast.cc
来自「编译工具」· CC 代码 · 共 2,492 行 · 第 1/5 页
CC
2,492 行
// -*- c++ -*-// Package : omniidl// idlast.cc Created on: 1999/10/20// 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:// // Abstract Syntax Tree objects and support functions// $Id: idlast.cc,v 1.16.2.13 2005/05/03 10:12:40 dgrisby Exp $// $Log: idlast.cc,v $// Revision 1.16.2.13 2005/05/03 10:12:40 dgrisby// Trying to redefine built in CORBA module types led to a segfault.//// Revision 1.16.2.12 2002/04/30 14:59:37 dgrisby// omniidl segfault when checking a non-existent identifier is not a forward.//// Revision 1.16.2.11 2001/11/08 16:31:20 dpg1// Minor tweaks.//// Revision 1.16.2.10 2001/10/29 17:42:42 dpg1// Support forward-declared structs/unions, ORB::create_recursive_tc().//// Revision 1.16.2.9 2001/10/17 16:48:32 dpg1// Minor error message tweaks//// Revision 1.16.2.8 2001/08/29 11:55:22 dpg1// Enumerator nodes record their value.//// Revision 1.16.2.7 2001/06/12 11:35:25 dpg1// Minor omniidl tweaks for valuetype.//// Revision 1.16.2.6 2001/06/08 17:12:22 dpg1// Merge all the bug fixes from omni3_develop.//// Revision 1.16.2.5 2001/03/13 10:32:11 dpg1// Fixed point support.//// Revision 1.16.2.4 2000/11/01 12:45:56 dpg1// Update to CORBA 2.4 specification.//// Revision 1.16.2.3 2000/10/27 16:31:08 dpg1// Clean up of omniidl dependencies and types, from omni3_develop.//// Revision 1.16.2.2 2000/10/10 10:18:50 dpg1// Update omniidl front-end from omni3_develop.//// Revision 1.14.2.9 2000/08/29 10:20:26 dpg1// Operations and attributes now have repository ids.//// Revision 1.14.2.8 2000/08/25 13:33:02 dpg1// Multiple comments preceding a declaration are now properly attached on// all platforms//// Revision 1.14.2.7 2000/08/07 15:34:36 dpg1// Partial back-port of long long from omni3_1_develop.//// Revision 1.14.2.6 2000/07/26 10:59:14 dpg1// Incorrect error report when inheriting typedef to forward declared// interface//// Revision 1.14.2.5 2000/06/08 14:36:19 dpg1// Comments and pragmas are now objects rather than plain strings, so// they can have file,line associated with them.//// Revision 1.14.2.4 2000/06/05 18:13:26 dpg1// Comments can be attached to subsequent declarations (with -K). Better// idea of most recent decl in operation declarations//// Revision 1.14.2.3 2000/03/16 17:35:21 dpg1// Bug with comments in input when keepComments is false.//// Revision 1.14.2.2 2000/03/07 10:31:26 dpg1// More sensible idea of the "most recent" declaration.//// Revision 1.14.2.1 2000/03/06 15:03:49 dpg1// Minor bug fixes to omniidl. New -nf and -k flags.//// Revision 1.14 2000/02/03 14:50:07 dpg1// Native declarations can now be used as types.//// Revision 1.13 2000/01/05 11:21:08 dpg1// Removed warning about signed/unsigned comparison.// * can only be the last character of a context key.//// Revision 1.12 1999/12/28 18:15:45 dpg1// Bounds of string constants now checked.//// Revision 1.11 1999/11/30 18:06:19 dpg1// Alias dereferencing bugs.//// Revision 1.10 1999/11/22 11:07:46 dpg1// Correctly report error with interface which tries to inherit from// CORBA::Object.//// Revision 1.9 1999/11/17 17:17:00 dpg1// Changes to remove static initialisation of objects.//// Revision 1.8 1999/11/04 17:15:52 dpg1// Typo.//// Revision 1.7 1999/11/02 17:07:27 dpg1// Changes to compile on Solaris.//// Revision 1.6 1999/11/01 20:19:57 dpg1// Support for union switch types declared inside the switch statement.//// Revision 1.5 1999/11/01 16:38:40 dpg1// Missed an update when adding recursive union detection.//// Revision 1.4 1999/11/01 10:05:00 dpg1// New file attribute to AST.//// Revision 1.3 1999/10/29 15:42:43 dpg1// DeclaredType() now takes extra DeclRepoId* argument.// Code to detect recursive structs and unions.//// Revision 1.2 1999/10/29 10:00:43 dpg1// Added code to find a value for the default case in a union.//// Revision 1.1 1999/10/27 14:05:59 dpg1// *** empty log message ***//#include <idlast.h>#include <idlrepoId.h>#include <idlvalidate.h>#include <idlerr.h>#include <idlconfig.h>#include <string.h>#include <ctype.h>// Globals from lexerextern FILE* yyin;extern char* currentFile;extern int yylineno;AST* AST::tree_ = 0;Decl* Decl::mostRecent_ = 0;Comment* Comment::mostRecent_ = 0;Comment* Comment::saved_ = 0;// Static error message functionsstatic voidcheckNotForward(const char* file, int line, IdlType* t){ if (!t) return; if (t->kind() == IdlType::ot_structforward) { StructForward* f = (StructForward*)((DeclaredType*)t)->decl(); if (!f->definition()) { char* ssn = f->scopedName()->toString(); IdlError(file, line, "Cannot use forward-declared struct '%s' before it is " "fully defined", ssn); IdlErrorCont(f->file(), f->line(), "('%s' forward-declared here)", f->identifier()); delete [] ssn; } } else if (t->kind() == IdlType::ot_unionforward) { UnionForward* f = (UnionForward*)((DeclaredType*)t)->decl(); if (!f->definition()) { char* ssn = f->scopedName()->toString(); IdlError(file, line, "Cannot use forward-declared union '%s' before it is " "fully defined", ssn); IdlErrorCont(f->file(), f->line(), "('%s' forward-declared here)", f->identifier()); delete [] ssn; } }}staticvoidcheckValidType(const char* file, int line, IdlType* t){ t = t->unalias(); if (!t) return; // Ignore if earlier errors. checkNotForward(file, line, t); if (t && t->kind() == IdlType::tk_sequence) { while (t && t->kind() == IdlType::tk_sequence) t = ((SequenceType*)t)->seqType()->unalias(); checkNotForward(file, line, t); }}// PragmavoidPragma::add(const char* pragmaText, const char* file, int line){ if (Decl::mostRecent()) Decl::mostRecent()->addPragma(pragmaText, file, line); else AST::tree()->addPragma(pragmaText, file, line);}// CommentvoidComment::add(const char* commentText, const char* file, int line){ if (Config::keepComments) { if (Config::commentsFirst) { if (saved_) { // C++ says that the order of value evaluation is undefined. // Comment's constructor sets mostRecent_, so the innocent- // looking mostRecent_->next_ = new Comment... does the wrong // thing with some compilers :-( Comment* mr = mostRecent_; mr->next_ = new Comment(commentText, file, line); } else saved_ = new Comment(commentText, file, line); } else { if (Decl::mostRecent()) Decl::mostRecent()->addComment(commentText, file, line); else AST::tree()->addComment(commentText, file, line); } }}voidComment::append(const char* commentText){ if (Config::keepComments) { assert(mostRecent_ != 0); char* newText = new char[(strlen(mostRecent_->commentText_) + strlen(commentText) + 1)]; strcpy(newText, mostRecent_->commentText_); strcat(newText, commentText); delete [] mostRecent_->commentText_; mostRecent_->commentText_ = newText; }}Comment*Comment::grabSaved(){ Comment* ret = saved_; saved_ = 0; return ret;}// ASTAST::AST() : declarations_(0), file_(0), pragmas_(0), lastPragma_(0), comments_(0), lastComment_(0) {}AST::~AST() { if (declarations_) delete declarations_; if (file_) delete [] file_; if (pragmas_) delete pragmas_; if (comments_) delete comments_;}voidAST::addPragma(const char* pragmaText, const char* file, int line){ Pragma* p = new Pragma(pragmaText, file, line); if (pragmas_) lastPragma_->next_ = p; else pragmas_ = p; lastPragma_ = p;}voidAST::addComment(const char* commentText, const char* file, int line){ Comment* p = new Comment(commentText, file, line); if (comments_) lastComment_->next_ = p; else comments_ = p; lastComment_ = p;}AST*AST::tree(){ if (!tree_) tree_ = new AST(); assert(tree_ != 0); return tree_;}IDL_BooleanAST::process(FILE* f, const char* name){ IdlType::init(); Scope::init(); yyin = f; currentFile = idl_strdup(name); Prefix::newFile(); tree()->setFile(name); int yr = yyparse(); if (yr) IdlError(currentFile, yylineno, "Syntax error"); if (Config::keepComments && Config::commentsFirst) tree()->comments_ = Comment::grabSaved(); Prefix::endOuterFile(); return IdlReportErrors();}voidAST::clear(){ if (tree_) { delete tree_; tree_ = 0; } Scope::clear(); Decl::clear(); Comment::clear();}voidAST::setFile(const char* file){ if (file_) { if (!strcmp(file_, file)) return; delete [] file_; } file_ = idl_strdup(file);}voidAST::setDeclarations(Decl* d){ assert(declarations_ == 0); declarations_ = d; // Validate the declarations AstValidateVisitor v; accept(v);}// Base DeclDecl::Decl(Kind kind, const char* file, int line, IDL_Boolean mainFile) : kind_(kind), file_(idl_strdup(file)), line_(line), mainFile_(mainFile), inScope_(Scope::current()), pragmas_(0), lastPragma_(0), comments_(0), lastComment_(0), next_(0){ last_ = this; mostRecent_ = this; if (Config::keepComments && Config::commentsFirst) comments_ = Comment::grabSaved();}Decl::~Decl(){ if (file_) delete [] file_; if (pragmas_) delete pragmas_; if (comments_) delete comments_; if (next_) delete next_;}Decl*Decl::scopedNameToDecl(const char* file, int line, const ScopedName* sn){ const Scope::Entry* se = Scope::current()->findScopedName(sn, file, line); if (se) { switch (se->kind()) { case Scope::Entry::E_MODULE: case Scope::Entry::E_DECL: case Scope::Entry::E_CALLABLE: case Scope::Entry::E_INHERITED: return se->decl(); default: { char* ssn = sn->toString(); IdlError(file, line, "'%s' is not a declaration", ssn); IdlErrorCont(se->file(), se->line(), "('%s' created here)", ssn); delete [] ssn; } } } return 0;}voidDecl::addPragma(const char* pragmaText, const char* file, int line){ Pragma* p = new Pragma(pragmaText, file, line); if (pragmas_) lastPragma_->next_ = p; else pragmas_ = p; lastPragma_ = p;}voidDecl::addComment(const char* commentText, const char* file, int line){ Comment* p = new Comment(commentText, file, line); if (comments_) lastComment_->next_ = p; else comments_ = p; lastComment_ = p;}// ModuleModule::Module(const char* file, int line, IDL_Boolean mainFile, const char* identifier) : Decl(D_MODULE, file, line, mainFile), DeclRepoId(identifier), definitions_(0){ Scope* s = Scope::current()->newModuleScope(identifier, file, line); Scope::current()->addModule(identifier, s, this, file, line); Scope::startScope(s); Prefix::newScope(identifier);}Module::~Module(){ if (definitions_) delete definitions_;}voidModule::finishConstruction(Decl* defs){ definitions_ = defs; Prefix::endScope(); Scope::endScope(); mostRecent_ = this;}// Interface
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?