Skip to content

Commit 8b45bd9

Browse files
committed
Check header files for DCE.
Fixes #45
1 parent 44a87bf commit 8b45bd9

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

source/projectGenerator_dce.cpp

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ bool ProjectGenerator::outputProjectDCE(const StaticList& includeDirs)
4545
findFiles(m_projectDir + "*.cpp", searchFiles, recurse);
4646
#endif
4747
// Ensure we can add extra items to the list without needing reallocs
48-
if (searchFiles.capacity() < searchFiles.size() + 250) {
49-
searchFiles.reserve(searchFiles.size() + 250);
50-
}
48+
searchFiles.reserve((searchFiles.size() * 3) + 250);
5149

5250
// Check for DCE constructs
5351
map<string, DCEParams> foundDCEUsage;
@@ -68,46 +66,61 @@ bool ProjectGenerator::outputProjectDCE(const StaticList& includeDirs)
6866
}
6967

7068
// Check if this file includes additional source files
71-
uint findPos = file.find(".c\"");
72-
while (findPos != string::npos) {
73-
// Check if this is an include
74-
uint findPos2 = file.rfind("#include \"", findPos);
75-
if ((findPos2 != string::npos) && (findPos - findPos2 < 50)) {
76-
// Get the name of the file
77-
findPos2 += 10;
78-
findPos += 2;
79-
string templateFile = file.substr(findPos2, findPos - findPos2);
80-
// check if file contains current project
81-
uint projName = templateFile.find(m_projectName);
82-
if (projName != string::npos) {
83-
templateFile = templateFile.substr(projName + m_projectName.length() + 1);
84-
}
85-
string found;
86-
string back = templateFile;
87-
templateFile = m_projectDir + back;
88-
if (!findFile(templateFile, found)) {
89-
templateFile = (m_configHelper.m_rootDirectory.length() > 0) ?
90-
m_configHelper.m_rootDirectory + '/' + back :
91-
back;
92-
if (!findFile(templateFile, found)) {
93-
templateFile = m_configHelper.m_solutionDirectory + m_projectName + '/' + back;
69+
vector<string> extensions = {".c\"", ".h\""};
70+
for (auto& ext : extensions) {
71+
uint findPos = file.find(ext);
72+
while (findPos != string::npos) {
73+
// Check if this is an include
74+
uint findPos2 = file.rfind("#include \"", findPos);
75+
if ((findPos2 != string::npos) && (findPos - findPos2 < 50)) {
76+
// Get the name of the file
77+
findPos2 += 10;
78+
findPos += 2;
79+
string templateFile = file.substr(findPos2, findPos - findPos2);
80+
// check if file contains current project
81+
uint projName = templateFile.find(m_projectName);
82+
if (projName != string::npos) {
83+
templateFile = templateFile.substr(projName + m_projectName.length() + 1);
84+
}
85+
if (templateFile.length() >= 3) {
86+
string found;
87+
string back = templateFile;
88+
templateFile = m_projectDir + back;
9489
if (!findFile(templateFile, found)) {
95-
templateFile = itFile->substr(0, itFile->rfind('/') + 1) + back;
90+
templateFile = (m_configHelper.m_rootDirectory.length() > 0) ?
91+
m_configHelper.m_rootDirectory + '/' + back :
92+
back;
9693
if (!findFile(templateFile, found)) {
97-
outputError("Failed to find included file " + back);
98-
return false;
94+
templateFile = m_configHelper.m_solutionDirectory + m_projectName + '/' + back;
95+
if (!findFile(templateFile, found)) {
96+
templateFile = itFile->substr(0, itFile->rfind('/') + 1) + back;
97+
if (!findFile(templateFile, found)) {
98+
templateFile = m_configHelper.m_solutionDirectory + '/' + back;
99+
if (!findFile(templateFile, found)) {
100+
// Fail only if this is a c file
101+
if (ext == extensions[0]) {
102+
outputError("Failed to find included file " + back);
103+
return false;
104+
}
105+
templateFile = "";
106+
}
107+
}
108+
}
109+
}
110+
}
111+
// Add the file to the list
112+
if (templateFile.length() >= 3 &&
113+
find(searchFiles.begin(), searchFiles.end(), templateFile) == searchFiles.end()) {
114+
m_configHelper.makeFileProjectRelative(templateFile, templateFile);
115+
if (find(searchFiles.begin(), searchFiles.end(), templateFile) == searchFiles.end()) {
116+
searchFiles.push_back(templateFile);
99117
}
100118
}
101119
}
102120
}
103-
// Add the file to the list
104-
if (find(searchFiles.begin(), searchFiles.end(), templateFile) == searchFiles.end()) {
105-
m_configHelper.makeFileProjectRelative(templateFile, templateFile);
106-
searchFiles.push_back(templateFile);
107-
}
121+
// Check for more
122+
findPos = file.find(ext, findPos + 1);
108123
}
109-
// Check for more
110-
findPos = file.find(".c\"", findPos + 1);
111124
}
112125
}
113126
#if !FORCEALLDCE

0 commit comments

Comments
 (0)