- enhancement: Open ".def" (Module definition file) file in editor when double click it in the project view.

- enhancement: When a dll project has .def file, use it when generating the dll file.
This commit is contained in:
Roy Qu 2024-03-27 15:32:30 +08:00
parent f88898ae1e
commit c941ae4cf8
6 changed files with 54 additions and 27 deletions

View File

@ -96,6 +96,8 @@ Red Panda C++ Version 2.27
- fix: An undefined macro is still missing the the parse result after #undef is removed.
- fix: If a class method is overloaded, only one of them is inherited by it's children.
- enhancement: Adjust function tip pos to prevent it from run outside the right window edge.
- enhancement: Open ".def" (Module definition file) file in editor when double click it in the project view.
- enhancement: When a dll project has .def file, use it when generating the dll file.
Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.

View File

@ -54,7 +54,8 @@ void ProjectCompiler::buildMakeFile()
void ProjectCompiler::createStandardMakeFile()
{
QFile file(mProject->makeFileName());
newMakeFile(file);
bool genModuleDef;
newMakeFile(file, genModuleDef);
QString executable = extractRelativePath(mProject->makeFileName(), mProject->executable());
QString exeTarget = escapeFilenameForMakefileTarget(executable);
QString exeCommand = escapeArgumentForMakefileRecipe(executable, false);
@ -84,20 +85,35 @@ void ProjectCompiler::createStaticMakeFile()
void ProjectCompiler::createDynamicMakeFile()
{
QFile file(mProject->makeFileName());
newMakeFile(file);
bool genModuleDef;
newMakeFile(file, genModuleDef);
QString executable = extractRelativePath(mProject->makeFileName(), mProject->executable());
QString exeTarget = escapeFilenameForMakefileTarget(executable);
QString exeCommand = escapeArgumentForMakefileRecipe(executable, false);
writeln(file, exeTarget + ": $(OBJ)");
writeln(file, exeTarget + ": $(DEF) $(OBJ)");
if (genModuleDef) {
if (mProject->options().isCpp) {
writeln(file, "\t$(CXX) -mdll $(LINKOBJ) -o " + exeCommand + " $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)");
writeln(file, "\t$(CXX) -mdll $(LINKOBJ) -o " + exeCommand + " $(LIBS) $(DEF) -Wl,--output-def,$(OUTPUT_DEF),--out-implib,$(STATIC)");
} else {
writeln(file, "\t$(CC) -mdll $(LINKOBJ) -o " + exeCommand + " $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)");
writeln(file, "\t$(CC) -mdll $(LINKOBJ) -o " + exeCommand + " $(LIBS) $(DEF) -Wl,--output-def,$(OUTPUT_DEF),--out-implib,$(STATIC)");
}
} else {
if (mProject->options().isCpp) {
writeln(file, "\t$(CXX) -mdll $(LINKOBJ) -o " + exeCommand + " $(LIBS) $(DEF) -Wl,--out-implib,$(STATIC)");
} else {
writeln(file, "\t$(CC) -mdll $(LINKOBJ) -o " + exeCommand + " $(LIBS) $(DEF) -Wl,--out-implib,$(STATIC)");
}
}
writeMakeObjFilesRules(file);
}
void ProjectCompiler::newMakeFile(QFile& file)
void ProjectCompiler::newMakeFile(QFile &file)
{
bool dummy;
newMakeFile(file, dummy);
}
void ProjectCompiler::newMakeFile(QFile& file, bool &genModuleDef)
{
// Create OBJ output directory
if (!mProject->options().objectOutput.isEmpty()) {
@ -120,7 +136,7 @@ void ProjectCompiler::newMakeFile(QFile& file)
writeMakeHeader(file);
// Writes definition list
writeMakeDefines(file);
writeMakeDefines(file, genModuleDef);
// Write PHONY and all targets
writeMakeTarget(file);
@ -152,24 +168,25 @@ void ProjectCompiler::writeMakeHeader(QFile &file)
writeln(file);
}
void ProjectCompiler::writeMakeDefines(QFile &file)
void ProjectCompiler::writeMakeDefines(QFile &file, bool &genModuleDef)
{
// Get list of object files
QStringList Objects;
QStringList LinkObjects;
QStringList cleanObjects;
QStringList moduleDefines;
genModuleDef = false;
// Create a list of object files
foreach(const PProjectUnit &unit, mProject->unitList()) {
if (!unit->compile() && !unit->link())
continue;
// Only process source files
QString RelativeName = extractRelativePath(mProject->directory(), unit->fileName());
FileType fileType = getFileType(RelativeName);
FileType fileType = getFileType(unit->fileName());
if (fileType == FileType::CSource || fileType == FileType::CppSource
|| fileType==FileType::GAS) {
QString relativeName = extractRelativePath(mProject->directory(), unit->fileName());
if (!mProject->options().objectOutput.isEmpty()) {
// ofile = C:\MyProgram\obj\main.o
QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput)
@ -181,14 +198,15 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
LinkObjects << relativeObjFile;
}
} else {
Objects << changeFileExt(RelativeName, OBJ_EXT);
cleanObjects << localizePath(changeFileExt(RelativeName, OBJ_EXT));
Objects << changeFileExt(relativeName, OBJ_EXT);
cleanObjects << localizePath(changeFileExt(relativeName, OBJ_EXT));
if (unit->link())
LinkObjects << changeFileExt(RelativeName, OBJ_EXT);
LinkObjects << changeFileExt(relativeName, OBJ_EXT);
}
}
if (fileType == FileType::ModuleDef)
moduleDefines.append(extractRelativePath(mProject->makeFileName(), unit->fileName()));
}
// Get windres file
QString objResFile;
QString cleanRes;
@ -299,9 +317,12 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
QString defFile = localizePath(changeFileExt(libOutputFile, DEF_EXT));
QString staticFile = localizePath(changeFileExt(libOutputFile, LIB_EXT));
writeln(file,"DEF = " + escapeFilenamesForMakefilePrerequisite(moduleDefines));
writeln(file,"STATIC = " + escapeFilenameForMakefilePrerequisite(staticFile));
writeln(file,"DEF = " + escapeArgumentForMakefileVariableValue(defFile, false));
writeln(file,"STATIC = " + escapeArgumentForMakefileVariableValue(staticFile, false));
genModuleDef = !moduleDefines.contains(defFile);
if (genModuleDef)
writeln(file,"OUTPUT_DEF = " + escapeFilenameForMakefilePrerequisite(defFile));
}
writeln(file);
}
@ -336,7 +357,7 @@ void ProjectCompiler::writeMakeClean(QFile &file)
}
if (mProject->options().type == ProjectType::DynamicLib) {
target +=" $(DEF) $(STATIC)";
target +=" $(STATIC)";
}
writeln(file, QString("\t-$(RM) %1 > %2 2>&1").arg(target,NULL_FILE));
writeln(file);

View File

@ -39,8 +39,9 @@ private:
void createStaticMakeFile();
void createDynamicMakeFile();
void newMakeFile(QFile& file);
void newMakeFile(QFile& file, bool &genModuleDef);
void writeMakeHeader(QFile& file);
void writeMakeDefines(QFile& file);
void writeMakeDefines(QFile& file, bool &genModuleDef);
void writeMakeTarget(QFile& file);
void writeMakeIncludes(QFile& file);
void writeMakeClean(QFile& file);

View File

@ -4392,17 +4392,16 @@ void CppParser::inheritClassStatement(const PStatement& derived, bool isStruct,
|| statement->kind == StatementKind::skDestructor)
continue;
if (derived->children.contains(statement->command)) {
// test if all children with the same name are not inherited.
// If so, it's overwrited and shouldn't inherit.
// Check if it's overwritten(hidden) by the derived
QList<PStatement> children = derived->children.values(statement->command);
bool hasInherited = false;
bool overwritten = false;
foreach(const PStatement& child, children) {
if (child->isInherited()) {
hasInherited = true;
if (!child->isInherited() && child->noNameArgs == statement->noNameArgs) {
overwritten = true;
break;
}
}
if (!hasInherited)
if (overwritten)
continue;
}
StatementAccessibility m_acc;

View File

@ -105,6 +105,9 @@ FileType getFileType(const QString &filename)
if (filename.endsWith(".vs",PATH_SENSITIVITY)) {
return FileType::VerticeShader;
}
if (filename.endsWith(".def",PATH_SENSITIVITY)) {
return FileType::ModuleDef;
}
QFileInfo info(filename);
if (info.suffix().isEmpty()) {
return FileType::Other;

View File

@ -49,6 +49,7 @@ enum class FileType{
Text, // text file
FragmentShader,
VerticeShader,
ModuleDef, // Windows Module Definition
Other // any others
};