-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for cpp:identifier
Metadata, and the Groundwork for xxx:identifier
Metadata in General
#3292
Add Support for cpp:identifier
Metadata, and the Groundwork for xxx:identifier
Metadata in General
#3292
Changes from all commits
6787ddb
87e3dde
11ac464
78529c0
ce37faf
9cda559
b2e8390
5427090
1cb67c5
329aeae
a3444f1
2c3b573
dca41be
3f54c9d
382482e
2e8b08d
3053c04
c4b3647
8a904fe
6eeb7ac
4084958
e013361
3dc8134
951a19b
3f92679
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ compareTag(const T& lhs, const T& rhs) | |
return lhs->tag() < rhs->tag(); | ||
} | ||
|
||
// NOTE: It is important that this list is kept in alphabetical order! | ||
constexpr string_view languages[] = {"cpp", "cs", "java", "js", "matlab", "php", "python", "ruby", "swift"}; | ||
|
||
// Forward declare things from Bison and Flex the parser can use. | ||
extern int slice_parse(); | ||
extern int slice_lineno; | ||
|
@@ -104,8 +107,6 @@ Slice::Metadata::Metadata(string rawMetadata, string file, int line) : GrammarBa | |
if (firstColonPos != string::npos) | ||
{ | ||
// Check if the metadata starts with a language prefix. | ||
// NOTE: It is important that this list is kept in alphabetical order! | ||
constexpr string_view languages[] = {"cpp", "cs", "java", "js", "matlab", "php", "python", "rb", "swift"}; | ||
string prefix = rawMetadata.substr(0, firstColonPos); | ||
bool hasLangPrefix = binary_search(&languages[0], &languages[sizeof(languages) / sizeof(*languages)], prefix); | ||
if (hasLangPrefix) | ||
|
@@ -562,27 +563,52 @@ Slice::Contained::name() const | |
string | ||
Slice::Contained::scoped() const | ||
{ | ||
return _scoped; | ||
return scope() + name(); | ||
} | ||
|
||
string | ||
Slice::Contained::scope() const | ||
{ | ||
string::size_type idx = _scoped.rfind("::"); | ||
assert(idx != string::npos); | ||
return string(_scoped, 0, idx + 2); | ||
string scoped; | ||
if (auto container = dynamic_pointer_cast<Contained>(_container)) | ||
{ | ||
scoped = container->scoped(); | ||
} | ||
return scoped + "::"; | ||
} | ||
|
||
string | ||
Slice::Contained::flattenedScope() const | ||
Slice::Contained::mappedName() const | ||
{ | ||
string s = scope(); | ||
string::size_type pos = 0; | ||
while ((pos = s.find("::", pos)) != string::npos) | ||
const string languageName = _unit->languageName(); | ||
assert(!languageName.empty()); | ||
|
||
// First check if any 'xxx:identifier' has been applied to this element. | ||
// If so, we return that instead of the element's Slice identifier. | ||
const string metadata = languageName + ":identifier"; | ||
if (auto customName = getMetadataArgs(metadata)) | ||
{ | ||
s.replace(pos, 2, "_"); | ||
return *customName; | ||
} | ||
return s; | ||
|
||
return _name; | ||
} | ||
|
||
string | ||
Slice::Contained::mappedScoped() const | ||
{ | ||
return mappedScope() + mappedName(); | ||
} | ||
|
||
string | ||
Slice::Contained::mappedScope() const | ||
{ | ||
string scoped; | ||
if (auto container = dynamic_pointer_cast<Contained>(_container)) | ||
{ | ||
scoped = container->mappedScoped(); | ||
} | ||
return scoped + "::"; | ||
} | ||
|
||
string | ||
|
@@ -1050,12 +1076,6 @@ Slice::Contained::Contained(const ContainerPtr& container, string name) | |
_container(container), | ||
_name(std::move(name)) | ||
{ | ||
ContainedPtr cont = dynamic_pointer_cast<Contained>(_container); | ||
if (cont) | ||
{ | ||
_scoped = cont->scoped(); | ||
} | ||
_scoped += "::" + _name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't much point to Most of the calls to |
||
assert(_unit); | ||
_file = _unit->currentFile(); | ||
_line = _unit->currentLine(); | ||
|
@@ -4544,19 +4564,25 @@ Slice::DataMember::DataMember( | |
// ---------------------------------------------------------------------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the code below this is to allow the compilers to inject their |
||
|
||
UnitPtr | ||
Slice::Unit::createUnit(bool all, const StringList& defaultFileMetadata) | ||
Slice::Unit::createUnit(string languageName, bool all, const StringList& defaultFileMetadata) | ||
{ | ||
MetadataList defaultMetadata; | ||
for (const auto& metadataString : defaultFileMetadata) | ||
{ | ||
defaultMetadata.push_back(make_shared<Metadata>(metadataString, "<command-line>", 0)); | ||
} | ||
|
||
UnitPtr unit{new Unit{all, std::move(defaultMetadata)}}; | ||
UnitPtr unit{new Unit{std::move(languageName), all, std::move(defaultMetadata)}}; | ||
unit->_unit = unit; | ||
return unit; | ||
} | ||
|
||
string | ||
Slice::Unit::languageName() const | ||
{ | ||
return _languageName; | ||
} | ||
|
||
void | ||
Slice::Unit::setDocComment(const string& comment) | ||
{ | ||
|
@@ -5006,15 +5032,19 @@ Slice::Unit::getTopLevelModules(const string& file) const | |
} | ||
} | ||
|
||
Slice::Unit::Unit(bool all, MetadataList defaultFileMetadata) | ||
Slice::Unit::Unit(string languageName, bool all, MetadataList defaultFileMetadata) | ||
: SyntaxTreeBase(nullptr), | ||
Container(nullptr), | ||
_languageName(std::move(languageName)), | ||
_all(all), | ||
_defaultFileMetadata(std::move(defaultFileMetadata)), | ||
_errors(0), | ||
_currentIncludeLevel(0) | ||
|
||
{ | ||
if (!languageName.empty()) | ||
{ | ||
assert(binary_search(&languages[0], &languages[sizeof(languages) / sizeof(*languages)], _languageName)); | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just swapped the order here to be consistent with other lists.