More work for includes, still commented out. Tokenizer needs #file handling

This commit is contained in:
Reijo Tomperi 2009-01-18 18:01:56 +00:00
parent 0177f77505
commit 3f98024215
2 changed files with 19 additions and 6 deletions

View File

@ -24,6 +24,7 @@
#include <algorithm>
#include <sstream>
#include <fstream>
#ifdef __BORLANDC__
#include <ctype>
@ -255,11 +256,10 @@ void Preprocessor::preprocess(std::istream &istr, std::string &processedFile, st
// Remove space characters that are after or before new line character
processedFile = removeSpaceNearNL(processedFile);
processedFile = replaceIfDefined(processedFile);
// TODO, uncomment below when handling of includes is implemented well enough
// processedFile = handleIncludes(processedFile);
processedFile = replaceIfDefined(processedFile);
// Get all possible configurations..
resultConfigurations = getcfgs(processedFile);
}
@ -487,9 +487,22 @@ std::string Preprocessor::handleIncludes(std::string code)
continue;
// filename contains now a file name e.g. "menu.h"
std::ifstream fin(filename.c_str());
std::string processedFile = Preprocessor::read(fin);
if (processedFile.length() > 0)
{
// Replace all tabs with spaces..
std::replace(processedFile.begin(), processedFile.end(), '\t', ' ');
// TODO, add the file here, except do not mess up with the line numbers.
// So me must tokenize, before we can append.
// Remove all indentation..
if (!processedFile.empty() && processedFile[0] == ' ')
processedFile.erase(0, processedFile.find_first_not_of(" "));
// Remove space characters that are after or before new line character
processedFile = removeSpaceNearNL(processedFile);
processedFile = "#file " + filename + "\n" + processedFile + "#endfile";
code.insert(pos, processedFile);
}
}
return code;

View File

@ -53,7 +53,7 @@ public:
void preprocess(std::istream &istr, std::string &processedFile, std::list<std::string> &resultConfigurations);
/** Just read the code into a string. Perform simple cleanup of the code */
std::string read(std::istream &istr);
static std::string read(std::istream &istr);
/**
* Get preprocessed code for a given configuration