String GetIncludePath0(const char *s, const char *filedir) { LTIMING("GetIncludePath0"); while(IsSpace(*s)) s++; int type = *s; if(type == '<' || type == '\"' || type == '?') { s++; String name; if(type == '<') type = '>'; while(*s != '\r' && *s != '\n') { if(*s == type) { if(type == '\"') { String fn = NormalizeSourcePath(name, filedir); if(FileExists(fn)) return fn; } String p = GetFileOnPath(name, GetIncludePath(), false); if(p.GetCount()) return NormalizeSourcePath(p); return Null; } name.Cat(*s++); } } return Null; }
void Ide::PreprocessInternal() { if(editor.GetLength() >= 1000000) // Sanity... return; int l = editor.GetCurrentLine(); PPSync(GetIncludePath()); String pfn = ConfigFile(GetFileTitle(editfile) + ".i.tmp"); Cpp cpp; StringStream in(editor.Get()); String p = NormalizeSourcePath(editfile); cpp.Preprocess(p, in, GetMasterFile(p)); Upp::SaveFile(pfn, cpp.output); HideBottom(); EditFile(pfn); EditAsText(); if(!editor.IsReadOnly()) ToggleReadOnly(); editor.SetCursor(editor.GetPos(l)); }
void GatherSources(const String& master_path, const String& path_, Vector<int>& parents) { RHITCOUNT("GatherSources"); String path = NormalizeSourcePath(path_); if(sSrcFile.Find(path) >= 0) return; int ii = sSrcFile.GetCount(); for(int i = 0; i < parents.GetCount(); i++) sIncludes.Add(MAKEQWORD(parents[i], ii)); sSrcFile.Add(path, master_path); parents.Add(ii); const PPFile& f = GetPPFile(path); for(int i = 0; i < f.includes.GetCount(); i++) { String p = GetIncludePath(f.includes[i], GetFileFolder(path)); if(p.GetCount()) GatherSources(master_path, p, parents); } parents.Drop(); }
const FlatPP& GetFlatPPFile(const char *path, Index<String>& visited) { LTIMING("GetFlatPPFile"); LLOG("GetFlatPPFile " << path); int q = sFlatPP.Find(path); if(q >= 0) { LLOG("From cache"); return sFlatPP[q]; } FlatPP& fp = sFlatPP.Add(path); const PPFile& pp = GetPPFile(path); int n = visited.GetCount(); visited.FindAdd(path); for(int i = 0; i < pp.item.GetCount(); i++) { const PPItem& m = pp.item[i]; if(m.type == PP_INCLUDE) { String s = GetIncludePath(m.text, GetFileFolder(path)); LLOG("#include " << m.text << " -> " << s); if(s.GetCount() && visited.Find(s) < 0) { visited.Add(s); const FlatPP& pp = GetFlatPPFile(s, visited); for(int i = 0; i < pp.segment_id.GetCount(); i++) fp.segment_id.FindAdd(pp.segment_id[i]); for(int i = 0; i < pp.usings.GetCount(); i++) fp.usings.FindAdd(pp.usings[i]); } } else if(m.type == PP_DEFINES) fp.segment_id.FindAdd(m.segment_id); else if(m.type == PP_USING) fp.usings.FindAdd(m.text); } visited.Trim(n); return fp; }
wxArrayString Compiler::GetDefaultIncludePaths() const { wxArrayString defaultPaths; if(GetCompilerFamily() == COMPILER_FAMILY_MINGW) { wxString ver = GetGCCVersion(); if(ver.IsEmpty()) { return defaultPaths; } // FIXME : support 64 bit compilers defaultPaths.Add(GetIncludePath("lib/gcc/mingw32/" + ver + "/include/c++")); defaultPaths.Add(GetIncludePath("lib/gcc/mingw32/" + ver + "/include/c++/mingw32")); defaultPaths.Add(GetIncludePath("lib/gcc/mingw32/" + ver + "/include/c++/backward")); defaultPaths.Add(GetIncludePath("lib/gcc/mingw32/" + ver + "/include")); defaultPaths.Add(GetIncludePath("include")); defaultPaths.Add(GetIncludePath("lib/gcc/mingw32/" + ver + "/include-fixed")); } else if(GetCompilerFamily() == COMPILER_FAMILY_CLANG || GetCompilerFamily() == COMPILER_FAMILY_GCC) { #ifndef __WXMSW__ defaultPaths = POSIXGetIncludePaths(); #endif } return defaultPaths; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- pANTLR3_INPUT_STREAM JalOpenInclude(char *Line) { int State, i; char *BaseName; char FileName[MAX_FILENAME_SIZE]; char FilePath[MAX_FILENAME_SIZE]; IncludeNameList *Inl; pANTLR3_INPUT_STREAM in; if (NoInclude) { CodeOutput(VERBOSE_M, "// Ignore include line %s\n", Line); return NULL; } // printf("// JalInclude line: %s\n", Line); //--------------------------------------------- // extract filename from include statement line //--------------------------------------------- State = 0; for (i=0; ((Line[i] != 0)&(State != 3)); i++) { switch(State) { case 0 : { // search for first whitespace if ((Line[i] == ' ') | (Line[i] == '\t')) { State = 1; } break; } case 1 : { // search for non-whitespace, which is start of filename/path if ((Line[i] != ' ') & (Line[i] != '\t')) { BaseName = &Line[i]; State = 2; } break; } case 2 : { // search for first whitespace, which is end of filename/path if ((Line[i] == ' ') | (Line[i] == '\t') | (Line[i] == '\r') | (Line[i] == '\n')) { Line[i] = 0; // terminate string State = 3; } break; } default : { CodeOutput(VERBOSE_ALL, "Error state: %d, i: %d\n", State, i); break; } } } CodeOutput(VERBOSE_M, "// include BaseName: _%s_\n", BaseName); // base filename retrieved. sprintf(FileName, "%s.jal", BaseName); //------------------------------------------ // check if file is already included //------------------------------------------ Inl = InlRoot; while (Inl) { if (strcmp(BaseName, Inl->FileName) == 0) { // file found CodeOutput(VERBOSE_M, "// File '%s' already included, so ignore now\n", BaseName); return NULL; } Inl = Inl->Next; } // not found, so add Inl = malloc(sizeof(IncludeNameList)); Inl->Next = InlRoot; Inl->FileName = CreateName(BaseName); InlRoot = Inl; //------------------------------------------ // try to open filename at current location. //------------------------------------------ strcpy(FilePath, FileName); CodeOutput(VERBOSE_L, "// Try first %s \n", FilePath); in = antlr3AsciiFileStreamNew(FilePath); if (in == NULL) { //------------------------------------------ // file not at current location, so // walk include path to find file. //------------------------------------------ GetIncludePath(NULL, 1); // reset include path for (;;) { if (GetIncludePath(FilePath, 0)) { // got a path. strcat(FilePath, FileName); CodeOutput(VERBOSE_L, "// Try path %s \n", FilePath); in = antlr3AsciiFileStreamNew(FilePath); if (in != NULL) break; // found the file! // else next file continue; } CodeOutput(VERBOSE_L, "// Path done without succes...\n"); break; } } if (in == NULL) { CodeOutput(VERBOSE_ERROR, "Error opening include file %s\n", FileName); exit(1); } // note: PUSHSTREAM macro only works in LEX context (not in this code, nor PARSER context). // So leave PUSHSTREAM in the gramar-file. return in; }
void ProcessFile( const string& fileName, const char* programName, FILE* fp, const vector<string>& includePath, string& prependDir, size_t nesting, set<string, less<string> >& cache, PrintFunc printFunc, bool& warn) { printFunc(fileName); if (nesting == 100) { ErrorExit(programName, "Infinite include file recursion? nesting level reached 100"); } PEGASUS_ASSERT(fp != NULL); // For each line in the file: char line[4096]; size_t lineNumber = 1; for (; fgets(line, sizeof(line), fp) != NULL; lineNumber++) { // Check for include directive: string path; char openDelim; if (line[0] == '#' && GetIncludePath(fileName, lineNumber, line, path, openDelim)) { // ATTN: danger! not distinguising between angle brack delimited // and quote delimited paths! set<string, less<string> >::const_iterator pos = cache.find(path); if (pos != cache.end()) { continue; } cache.insert(path); string fullPath; FILE* includeFp = FindFile(includePath, prependDir, path, openDelim, fullPath); if (!includeFp) { if (warn) { string message = "header file not found: " + path + " included from " + fileName; Warning(programName, message); } } else { ProcessFile(fullPath, programName, includeFp, includePath, prependDir, nesting + 1, cache, printFunc, warn); } } } fclose(fp); }
void ProcessFile( const string& objectFileName, const string& fileName, FILE* fp, const vector<string>& includePath, size_t nesting, set<string, less<string> >& cache) { PrintDependency(objectFileName, fileName); if (nesting == 100) { ErrorExit( "Infinite include file recursion? nesting level reached 100"); } assert(fp != NULL); // For each line in the file: char line[4096]; size_t lineNumber = 1; for (; fgets(line, sizeof(line), fp) != NULL; lineNumber++) { // Check for include directive: string path; char openDelim; if (line[0] == '#' && GetIncludePath(fileName, lineNumber, line, path, openDelim)) { // ATTN: danger! not distinguising between angle brack delimited // and quote delimited paths! set<string, less<string> >::const_iterator pos = cache.find(path); if (pos != cache.end()) continue; cache.insert(path); string fullPath; FILE* fp = FindFile(includePath, path, openDelim, fullPath); if (!fp) { if (warn) { Warning("header file not found: " + path + " included from " + objectFileName); } } else { ProcessFile(objectFileName, fullPath, fp, includePath, nesting + 1, cache); } } } fclose(fp); }