1 // $Id: jikesapi.h,v 1.19 2004/02/28 17:09:45 elliott-oss Exp $ -*- c++ -*- 2 // 3 // This software is subject to the terms of the IBM Jikes Compiler 4 // License Agreement available at the following URL: 5 // http://ibm.com/developerworks/opensource/jikes. 6 // Copyright (C) 1996, 1999, 2000, 2001, 2002 International Business 7 // Machines Corporation and others. All Rights Reserved. 8 // You must accept the terms of that agreement to use this software. 9 // 10 11 #ifndef JIKES_API_H_FLAG_ 12 #define JIKES_API_H_FLAG_ 13 14 class JikesOption 15 { 16 public: 17 char* bootclasspath; // Location of the libraries 18 char* extdirs; // Location of external drop-in jars 19 char* classpath; // Location of source and user class files 20 char* sourcepath; // Location of source files only 21 char* directory; // Target directory for output 22 char* encoding; // Character encoding name 23 24 // Each of these fields is a boolean value 25 // 0 if false, non-zero if true 26 int nowrite; // Don't generate output, useful with verbose 27 int deprecation; // Warn about deprecated code 28 int optimize; // Enable optimizations 29 int verbose; // Verbosely track compilation progress 30 int depend; // Require full dependency check 31 int old_classpath_search_order; // Use older classpath search order 32 int help; // Display a usage help message 33 int version; // Display a version message 34 35 enum DebugLevel 36 { 37 NONE = 0, 38 SOURCE = 1, 39 LINES = 2, 40 VARS = 4 41 }; 42 43 enum ReleaseLevel 44 { 45 UNKNOWN, 46 SDK1_1, 47 SDK1_2, 48 SDK1_3, 49 SDK1_4, 50 SDK1_4_2, 51 SDK1_5 52 }; 53 54 // This field can be 0 through 7 to represent all debug level combinations. 55 int g; // Annotate class files with debugging information 56 57 // 58 // The JDK release number of the syntax rules to obey (for example, 59 // assert was added in 1.4), as well as the VM level to target. 60 // 61 ReleaseLevel source; 62 ReleaseLevel target; 63 64 enum ToleranceLevel 65 { 66 NO_WARNINGS = 0, 67 CAUTIONS_ARE_ERRORS = 1, 68 WARNINGS_ARE_ERRORS = 2, 69 DEFAULT = 4 70 }; 71 72 ToleranceLevel tolerance; 73 74 virtual ~JikesOption(); 75 76 protected: 77 JikesOption(); 78 }; 79 80 class JikesError 81 { 82 public: 83 enum JikesErrorSeverity 84 { 85 JIKES_ERROR, 86 JIKES_CAUTION, 87 JIKES_WARNING 88 }; 89 90 virtual JikesErrorSeverity getSeverity() = 0; 91 92 /** 93 * The filename where the error occurred. The caller should not delete 94 * the return value. 95 */ 96 virtual const char* getFileName() = 0; 97 98 virtual int getLeftLineNo() = 0; 99 virtual int getLeftColumnNo() = 0; 100 virtual int getRightLineNo() = 0; 101 virtual int getRightColumnNo() = 0; 102 103 /** 104 * Returns message describing error. The caller should not delete the 105 * return value. 106 */ 107 virtual const wchar_t* getErrorMessage() = 0; 108 109 /** 110 * Returns formatted error report. The caller should not delete the 111 * return value. 112 */ 113 virtual const wchar_t* getErrorReport() = 0; 114 115 protected: 116 const char* getSeverityString(); 117 }; 118 119 /** 120 * API to jikes compiler. 121 */ 122 class JikesAPI 123 { 124 public: 125 126 JikesAPI(); 127 virtual ~JikesAPI(); 128 129 /** 130 * Returns instance of current compiler options. 131 * Returned pointer can be used to modify current compiler options. 132 */ 133 virtual JikesOption* getOptions(); 134 135 /** 136 * Creates instance of compiler options, 137 * corresponding to given command line parameters. 138 * 139 * @return list of java file names found on command line 140 * Caller should not attempt to manage the memory returned 141 * by this method as it can be freed during another call 142 * to parseOptions() or when this object is destroyed. 143 */ 144 virtual char** parseOptions(int argc, char** argv); 145 146 /** 147 * Compile given list of files using current compiler options. 148 */ 149 virtual int compile(char** filenames); 150 151 /** 152 * Jikes API implements singelton pattern. 153 * This is a way to get instance of it. 154 */ 155 static JikesAPI* getInstance(); 156 157 /** 158 * This method will be called for each error reported. 159 */ 160 virtual void reportError(JikesError* error); 161 162 /** 163 * Define the virtual base class for all Readers. 164 * A pointer to an object of this type is returned by JikesAPI::read() 165 */ 166 class FileReader 167 { 168 public: ~FileReader()169 virtual ~FileReader() {} 170 171 // If the file is unreadable an object should still be created but 172 // GetBuffer() should return NULL. 173 virtual const char* getBuffer() = 0; 174 // If the file is unreadable GetBufferSize() is undefined. 175 virtual size_t getBufferSize() = 0; 176 }; 177 178 /** 179 * Define the virtual base class for all WriteObjects. 180 * A pointer to an object of this type is returned by JikesAPI::write() 181 */ 182 class FileWriter 183 { 184 public: FileWriter(size_t mS)185 FileWriter(size_t mS) : maxSize(mS) {} ~FileWriter()186 virtual ~FileWriter() {} 187 188 size_t write(const unsigned char* data, size_t size); 189 virtual int isValid() = 0; 190 191 private: 192 // Guaranteed not to be called with a combined total of more than 193 // maxSize bytes during the lifespan of the object. 194 virtual size_t doWrite(const unsigned char* data, size_t size) = 0; 195 size_t maxSize; 196 }; 197 198 virtual int stat(const char* filename, struct stat* status); 199 200 virtual FileReader* read(const char* filename); 201 virtual FileWriter* write(const char* filename, size_t bytes); 202 203 private: 204 void cleanupOptions(); // Helper to delete option and parsedOptions 205 206 JikesOption* option; 207 char** parsedOptions; 208 209 static JikesAPI* instance; 210 }; 211 212 #endif // JIKES_API_H_FLAG_ 213