Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:28

0001 // @(#)root/rint:$Id$
0002 // Author: Christian Lacunza <lacunza@cdfsg6.lbl.gov>   27/04/99
0003 
0004 // Modified by Artur Szostak <artur@alice.phy.uct.ac.za> : 1 June 2003
0005 //   Added support for namespaces.
0006 
0007 /*************************************************************************
0008  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0009  * All rights reserved.                                                  *
0010  *                                                                       *
0011  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0012  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0013  *************************************************************************/
0014 
0015 #ifndef ROOT_TTabCom
0016 #define ROOT_TTabCom
0017 
0018 
0019 ////////////////////////////////////////////////////////////////////////////
0020 //                                                                        //
0021 // TTabCom                                                                //
0022 //                                                                        //
0023 // This class performs basic tab completion.                              //
0024 // You should be able to hit [TAB] to complete a partially typed:         //
0025 //                                                                        //
0026 //   username                                                             //
0027 //   environment variable                                                 //
0028 //   preprocessor directive                                               //
0029 //   pragma                                                               //
0030 //   filename (with a context-sensitive path)                             //
0031 //   public member function or data member                                //
0032 //   global variable, function, or class name                             //
0033 //                                                                        //
0034 // Also, something like gWhatever->Func([TAB] will print the appropriate  //
0035 // list of prototypes. For a list of some limitations see the source.     //
0036 //                                                                        //
0037 ////////////////////////////////////////////////////////////////////////////
0038 
0039 #include "TString.h"
0040 #include "TRegexp.h"
0041 
0042 #define MAX_LEN_PAT 1024               // maximum length of a pattern
0043 #define dblquote(x) "\"" << x << "\""
0044 
0045 // forward declarations
0046 class TList;
0047 class TListIter;
0048 class TSeqCollection;
0049 class TClass;
0050 
0051 
0052 class TTabCom {
0053 
0054 public: // constructors
0055    TTabCom();
0056    virtual ~TTabCom();
0057 
0058 public: // typedefs
0059    typedef TList     TContainer;
0060    typedef TListIter TContIter;
0061 
0062 public: // member functions
0063    Int_t Hook(char *buf, int *pLoc, std::ostream& out);
0064 
0065    const TSeqCollection* GetListOfClasses();
0066    const TSeqCollection* GetListOfCppDirectives();
0067    const TSeqCollection* GetListOfFilesInPath( const char path[] );
0068    const TSeqCollection* GetListOfEnvVars();
0069    TCollection* GetListOfGlobalFunctions();
0070    const TSeqCollection* GetListOfGlobals();
0071    const TSeqCollection* GetListOfPragmas();
0072    const TSeqCollection* GetListOfSysIncFiles();
0073    const TSeqCollection* GetListOfUsers();
0074 
0075    void ClearClasses();
0076    void ClearCppDirectives();
0077    void ClearEnvVars();
0078    void ClearFiles();
0079    void ClearGlobalFunctions();
0080    void ClearGlobals();
0081    void ClearPragmas();
0082    void ClearSysIncFiles();
0083    void ClearUsers();
0084 
0085    void ClearAll();
0086 
0087    void RehashClasses();
0088    void RehashCppDirectives();
0089    void RehashEnvVars();
0090    void RehashFiles();
0091    void RehashGlobalFunctions();
0092    void RehashGlobals();
0093    void RehashPragmas();
0094    void RehashSysIncFiles();
0095    void RehashUsers();
0096 
0097    void RehashAll();
0098 
0099 public: // static utility functions
0100    static Char_t   AllAgreeOnChar( int i, const TSeqCollection* pList, Int_t& nGoodStrings );
0101    static void     AppendListOfFilesInDirectory( const char dirName[], TSeqCollection* pList );
0102    static TString  DetermineClass( const char varName[] ); // TROOT
0103    static Bool_t   ExcludedByFignore( TString s );
0104    static TString  GetSysIncludePath(); // TROOT
0105    static Bool_t   IsDirectory( const char fileName[] ); // TSystem
0106    static TSeqCollection* NewListOfFilesInPath( const char path[] );
0107    static Bool_t   PathIsSpecifiedInFileName( const TString& fileName );
0108    static void     NoMsg( Int_t errorLevel );
0109 
0110 public: // enums
0111    enum {kDebug = 17}; // set gDebug==TTabCom::kDebug for debugging output
0112 
0113    enum EContext_t {
0114       kUNKNOWN_CONTEXT=-1,
0115       // first enum (not counting "kUNKNOWN_CONTEXT") must
0116       // cast to zero because these enums will be used to
0117       // index arrays of size "kNUM_PAT"
0118       // ---------------
0119 
0120       // user names and environment variables should come first
0121       kSYS_UserName,
0122       kSYS_EnvVar, // environment variables
0123 
0124       // file descriptor redirection should almost come first
0125       kCINT_stdout,  // stdout
0126       kCINT_stderr,  // stderr
0127       kCINT_stdin,   // stdin
0128 
0129       // CINT "." instructions
0130       // the position of these guys is irrelevant since each of
0131       // these commands will always be the only command on the line.
0132       kCINT_Edit,  // .E
0133       kCINT_Load,  // .L
0134       kCINT_Exec,  // .x
0135       kCINT_EXec,  // .X
0136 
0137       // specific preprocessor directives.
0138       kCINT_pragma,
0139       kCINT_includeSYS,  // system files
0140       kCINT_includePWD,  // local files
0141 
0142       // specific preprocessor directives
0143       // must come before general preprocessor directives
0144 
0145       // general preprocessor directives
0146       // must come after specific preprocessor directives
0147       kCINT_cpp,
0148 
0149       // specific member accessing
0150       // should come before general member accessing
0151       kROOT_Load,
0152 
0153       // random files
0154       /******************************************************************/
0155       /*                                                                */
0156       /* file names should come before member accessing                 */
0157       /*                                                                */
0158       /* (because otherwise "/tmp/a.cc" might look like you're trying   */
0159       /* to access member "cc" of some object "a")                      */
0160       /*                                                                */
0161       /* but after anything that requires a specific path.              */
0162       /*                                                                */
0163       /******************************************************************/
0164       kSYS_FileName,
0165 
0166       // time to print prototype
0167       kCXX_NewProto, // kCXX_NewProto must come before kCXX_ConstructorProto
0168       kCXX_ConstructorProto, // kCXX_ConstructorProto this must come before kCXX_GlobalProto
0169       kCXX_ScopeProto,
0170       kCXX_DirectProto,
0171       kCXX_IndirectProto,
0172 
0173       // general member access
0174       // should come after specific member access
0175       kCXX_ScopeMember,
0176       kCXX_DirectMember,
0177       kCXX_IndirectMember,
0178 
0179       // arbitrary global identifiers
0180       // should really come last
0181       kCXX_Global,
0182       kCXX_GlobalProto,
0183 
0184 
0185       // ------- make additions above this line ---------
0186       kNUM_PAT // kNUM_PAT must be last. (to fix array size)
0187    };
0188 
0189 private: // member functions
0190    TTabCom(const TTabCom &) = delete;
0191    TTabCom& operator=(const TTabCom&) = delete;
0192 
0193    Int_t      Complete(const TRegexp& re, const TSeqCollection* pListOfCandidates,
0194                        const char appendage[], std::ostream& out, TString::ECaseCompare cmp = TString::kExact);
0195    void       CopyMatch(char *dest, int dest_len, const char *localName, const char *appendage = nullptr, const char *fullName = nullptr) const;
0196    EContext_t DetermineContext() const;
0197    TString    DeterminePath( const TString& fileName, const char defaultPath[] ) const;
0198    TString    ExtendPath( const char originalPath[], TString newBase ) const;
0199    void       InitPatterns();
0200    TClass*    MakeClassFromClassName( const char className[] ) const;
0201    TClass*    TryMakeClassFromClassName( const char className[] ) const;
0202    TClass*    MakeClassFromVarName( const char varName[], EContext_t& context,
0203                   int iter=0);
0204    void       SetPattern( EContext_t handle, const char regexp[] );
0205    int        ParseReverse(const char *var_str, int start);
0206 
0207 private: // data members
0208    TSeqCollection* fpClasses;
0209    ULong64_t       fPrevInterpMarker;
0210    TSeqCollection* fpDirectives;
0211    TSeqCollection* fpEnvVars;
0212    TSeqCollection* fpFiles;
0213    TSeqCollection* fpGlobals;
0214    TSeqCollection* fpPragmas;
0215    TSeqCollection* fpSysIncFiles;
0216    TSeqCollection* fpUsers;
0217 
0218    char* fBuf;  // initialized by Hook()
0219    int*  fpLoc; // initialized by Hook()
0220 
0221    Pattern_t   fPat[ kNUM_PAT ][ MAX_LEN_PAT ];  // array of patterns
0222    const char* fRegExp[ kNUM_PAT ];              // corresponding regular expression plain text
0223    Bool_t fVarIsPointer;                         // frodo: pointer or not flag
0224    Int_t  fLastIter;                             // frodo: iteration counter for recursive MakeClassFromVarName
0225 
0226    ClassDef(TTabCom,0)  //Perform command line completion when hitting <TAB>
0227 };
0228 
0229 R__EXTERN TTabCom *gTabCom;
0230 
0231 #endif