Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5977: Some restructuring to make the parsing logic reusable outside …
…the ThreadedDeclParser.
- Loading branch information
1 parent
df14b27
commit a9896bc
Showing
10 changed files
with
223 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "idecltypes.h" | ||
|
||
namespace decl | ||
{ | ||
|
||
class DeclarationFile | ||
{ | ||
public: | ||
// mod-relative path | ||
std::string fullPath; | ||
|
||
// The default type of this file, used for all | ||
// declarations without explicitly declared type | ||
decl::Type defaultDeclType; | ||
|
||
bool operator< (const DeclarationFile& other) const | ||
{ | ||
if (defaultDeclType < other.defaultDeclType) | ||
{ | ||
return true; | ||
} | ||
|
||
if (defaultDeclType == other.defaultDeclType) | ||
{ | ||
return fullPath < other.fullPath; | ||
} | ||
|
||
return false; | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 10 additions & 13 deletions
23
radiantcore/decl/DeclarationParser.h → radiantcore/decl/DeclarationFileParser.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
#pragma once | ||
|
||
#include "ideclmanager.h" | ||
|
||
#include "parser/DefBlockTokeniser.h" | ||
#include "parser/ThreadedDeclParser.h" | ||
#include "DeclarationFile.h" | ||
|
||
namespace decl | ||
{ | ||
|
||
class DeclarationManager; | ||
|
||
class DeclarationParser : | ||
public parser::ThreadedDeclParser<void> | ||
class DeclarationFileParser | ||
{ | ||
private: | ||
DeclarationManager& _owner; | ||
Type _defaultDeclType; | ||
|
||
std::map<std::string, IDeclarationParser::Ptr> _parsersByTypename; | ||
IDeclarationParser::Ptr _defaultTypeParser; | ||
|
||
std::set<DeclarationFile> _parsedFiles; | ||
std::map<Type, NamedDeclarations> _parsedDecls; | ||
|
||
std::vector<DeclarationBlockSyntax> _unrecognisedBlocks; | ||
|
||
public: | ||
DeclarationParser(DeclarationManager& owner, Type declType, | ||
const std::string& baseDir, const std::string& extension, | ||
const std::map<std::string, IDeclarationParser::Ptr>& parsersByTypename); | ||
DeclarationFileParser(Type declType, const std::map<std::string, IDeclarationParser::Ptr>& parsersByTypename); | ||
|
||
void parse(std::istream& stream, const vfs::FileInfo& fileInfo, const std::string& modDir); | ||
|
||
protected: | ||
void parse(std::istream& stream, const vfs::FileInfo& fileInfo, const std::string& modDir) override; | ||
void onFinishParsing() override; | ||
std::map<Type, NamedDeclarations>& getParsedDecls(); | ||
const std::set<DeclarationFile>& getParsedFiles() const; | ||
const std::vector<DeclarationBlockSyntax>& getUnrecognisedBlocks() const; | ||
|
||
private: | ||
void parseBlock(IDeclarationParser& parser, const DeclarationBlockSyntax& block); | ||
IDeclarationParser::Ptr getParserByType(Type declType) const; | ||
void parseBlock(IDeclarationParser& parser, const DeclarationBlockSyntax& blockSyntax); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "DeclarationFolderParser.h" | ||
|
||
#include "DeclarationManager.h" | ||
|
||
namespace decl | ||
{ | ||
|
||
DeclarationFolderParser::DeclarationFolderParser(DeclarationManager& owner, Type declType, | ||
const std::string& baseDir, const std::string& extension, | ||
const std::map<std::string, IDeclarationParser::Ptr>& parsersByTypename) : | ||
ThreadedDeclParser<void>(declType, baseDir, extension, 1), | ||
_owner(owner), | ||
_fileParser(declType, parsersByTypename), | ||
_defaultDeclType(declType) | ||
{} | ||
|
||
void DeclarationFolderParser::parse(std::istream& stream, const vfs::FileInfo& fileInfo, const std::string& modDir) | ||
{ | ||
_fileParser.parse(stream, fileInfo, modDir); | ||
} | ||
|
||
void DeclarationFolderParser::onFinishParsing() | ||
{ | ||
// Submit all parsed declarations to the decl manager | ||
_owner.onParserFinished(_defaultDeclType, _fileParser.getParsedDecls(), _fileParser.getUnrecognisedBlocks(), _fileParser.getParsedFiles()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "DeclarationFile.h" | ||
#include "DeclarationFileParser.h" | ||
#include "ideclmanager.h" | ||
|
||
#include "parser/ThreadedDeclParser.h" | ||
|
||
namespace decl | ||
{ | ||
|
||
class DeclarationManager; | ||
|
||
// Threaded parser processing all files in the configured decl folder | ||
// Submits all parsed declarations to the IDeclarationManager when finished | ||
class DeclarationFolderParser : | ||
public parser::ThreadedDeclParser<void> | ||
{ | ||
private: | ||
DeclarationManager& _owner; | ||
|
||
DeclarationFileParser _fileParser; | ||
Type _defaultDeclType; | ||
|
||
public: | ||
DeclarationFolderParser(DeclarationManager& owner, Type declType, | ||
const std::string& baseDir, const std::string& extension, | ||
const std::map<std::string, IDeclarationParser::Ptr>& parsersByTypename); | ||
|
||
protected: | ||
void parse(std::istream& stream, const vfs::FileInfo& fileInfo, const std::string& modDir) override; | ||
void onFinishParsing() override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.