-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use AST for checking if a filename is valid or not
- Loading branch information
Showing
10 changed files
with
130 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "filename/ast-filename.h" | ||
#include "filename/filename-parser.h" | ||
#include "filename/filename-resolution-visitor.h" | ||
#include "filename/ast/filename-node-root.h" | ||
|
||
|
||
AstFilename::AstFilename(const QString &str) | ||
: m_parser(str) | ||
{} | ||
|
||
void AstFilename::parse() | ||
{ | ||
auto ast = m_parser.parseRoot(); | ||
if (m_parser.error().isEmpty()) { | ||
m_ast = ast; | ||
|
||
FilenameResolutionVisitor resolutionVisitor; | ||
m_tokens = resolutionVisitor.run(*m_ast); | ||
} | ||
|
||
m_parsed = true; | ||
} | ||
|
||
const QString &AstFilename::error() | ||
{ | ||
if (!m_parsed) { | ||
parse(); | ||
} | ||
|
||
return m_parser.error(); | ||
} | ||
|
||
FilenameNodeRoot *AstFilename::ast() | ||
{ | ||
if (!m_parsed) { | ||
parse(); | ||
} | ||
|
||
return m_ast; | ||
} | ||
|
||
const QSet<QString> &AstFilename::tokens() | ||
{ | ||
if (!m_parsed) { | ||
parse(); | ||
} | ||
|
||
return m_tokens; | ||
} |
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,30 @@ | ||
#ifndef AST_FILENAME_H | ||
#define AST_FILENAME_H | ||
|
||
#include <QSet> | ||
#include <QString> | ||
#include "filename/filename-parser.h" | ||
|
||
|
||
struct FilenameNodeRoot; | ||
|
||
class AstFilename | ||
{ | ||
public: | ||
explicit AstFilename(const QString &str); | ||
const QString &error(); | ||
FilenameNodeRoot *ast(); | ||
const QSet<QString> &tokens(); | ||
|
||
protected: | ||
void parse(); | ||
|
||
private: | ||
FilenameParser m_parser; | ||
bool m_parsed = false; | ||
|
||
FilenameNodeRoot *m_ast = nullptr; | ||
QSet<QString> m_tokens; | ||
}; | ||
|
||
#endif // AST_FILENAME_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,39 +1,12 @@ | ||
#ifndef FILENAME_CACHE_H | ||
#define FILENAME_CACHE_H | ||
|
||
#include <QMap> | ||
#include <QSharedPointer> | ||
#include <QString> | ||
#include "filename/ast/filename-node-root.h" | ||
#include "filename/filename-parser.h" | ||
#include "flyweight-cache.h" | ||
#include "filename/ast-filename.h" | ||
|
||
|
||
class FilenameCache | ||
class FilenameCache : public FlyweightCache<QString, AstFilename> | ||
{ | ||
public: | ||
static QSharedPointer<FilenameNodeRoot> Get(const QString &key); | ||
|
||
private: | ||
static QMap<QString, QWeakPointer<FilenameNodeRoot>> Map; | ||
}; | ||
|
||
|
||
QMap<QString, QWeakPointer<FilenameNodeRoot>> FilenameCache::Map; | ||
|
||
QSharedPointer<FilenameNodeRoot> FilenameCache::Get(const QString &key) | ||
{ | ||
auto it = Map.find(key); | ||
if (it != Map.end()) { | ||
return QSharedPointer<FilenameNodeRoot>(it.value()); | ||
} | ||
|
||
FilenameParser parser(key); | ||
const QSharedPointer<FilenameNodeRoot> shared(parser.parseRoot()); | ||
|
||
const QWeakPointer<FilenameNodeRoot> weak(shared); | ||
Map.insert(key, weak); | ||
|
||
return shared; | ||
} | ||
|
||
#endif // FILENAME_CACHE_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
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
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
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