Skip to content
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

Improve the Parser's API and Storage of Metadata #3003

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 115 additions & 109 deletions cpp/src/Slice/Grammar.cpp

Large diffs are not rendered by default.

60 changes: 33 additions & 27 deletions cpp/src/Slice/Grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ opt_semicolon
// ----------------------------------------------------------------------
file_metadata
// ----------------------------------------------------------------------
: ICE_FILE_METADATA_OPEN string_list ICE_FILE_METADATA_CLOSE
: ICE_FILE_METADATA_OPEN metadata_list ICE_FILE_METADATA_CLOSE
{
$$ = $2;
}
Expand All @@ -207,13 +207,13 @@ file_metadata
// ----------------------------------------------------------------------
metadata
// ----------------------------------------------------------------------
: ICE_METADATA_OPEN string_list ICE_METADATA_CLOSE
: ICE_METADATA_OPEN metadata_list ICE_METADATA_CLOSE
{
$$ = $2;
}
| %empty
{
$$ = make_shared<StringListTok>();
$$ = make_shared<MetadataListTok>();
}
;

Expand All @@ -222,15 +222,15 @@ definitions
// ----------------------------------------------------------------------
: definitions file_metadata
{
auto metadata = dynamic_pointer_cast<StringListTok>($2);
auto metadata = dynamic_pointer_cast<MetadataListTok>($2);
if (!metadata->v.empty())
{
currentUnit->addFileMetadata(metadata->v);
}
}
| definitions metadata definition
{
auto metadata = dynamic_pointer_cast<StringListTok>($2);
auto metadata = dynamic_pointer_cast<MetadataListTok>($2);
auto contained = dynamic_pointer_cast<Contained>($3);
if (contained && !metadata->v.empty())
{
Expand Down Expand Up @@ -987,7 +987,7 @@ data_members
// ----------------------------------------------------------------------
: metadata data_member ';' data_members
{
auto metadata = dynamic_pointer_cast<StringListTok>($1);
auto metadata = dynamic_pointer_cast<MetadataListTok>($1);
auto contained = dynamic_pointer_cast<Contained>($2);
if (contained && !metadata->v.empty())
{
Expand Down Expand Up @@ -1468,7 +1468,7 @@ operations
// ----------------------------------------------------------------------
: metadata operation ';' operations
{
auto metadata = dynamic_pointer_cast<StringListTok>($1);
auto metadata = dynamic_pointer_cast<MetadataListTok>($1);
auto contained = dynamic_pointer_cast<Contained>($2);
if (contained && !metadata->v.empty())
{
Expand Down Expand Up @@ -1535,15 +1535,15 @@ sequence_def
: ICE_SEQUENCE '<' metadata type '>' ICE_IDENTIFIER
{
auto ident = dynamic_pointer_cast<StringTok>($6);
auto metadata = dynamic_pointer_cast<StringListTok>($3);
auto metadata = dynamic_pointer_cast<MetadataListTok>($3);
auto type = dynamic_pointer_cast<Type>($4);
ContainerPtr cont = currentUnit->currentContainer();
$$ = cont->createSequence(ident->v, type, metadata->v);
}
| ICE_SEQUENCE '<' metadata type '>' keyword
{
auto ident = dynamic_pointer_cast<StringTok>($6);
auto metadata = dynamic_pointer_cast<StringListTok>($3);
auto metadata = dynamic_pointer_cast<MetadataListTok>($3);
auto type = dynamic_pointer_cast<Type>($4);
ContainerPtr cont = currentUnit->currentContainer();
$$ = cont->createSequence(ident->v, type, metadata->v); // Dummy
Expand All @@ -1557,19 +1557,19 @@ dictionary_def
: ICE_DICTIONARY '<' metadata type ',' metadata type '>' ICE_IDENTIFIER
{
auto ident = dynamic_pointer_cast<StringTok>($9);
auto keyMetadata = dynamic_pointer_cast<StringListTok>($3);
auto keyMetadata = dynamic_pointer_cast<MetadataListTok>($3);
auto keyType = dynamic_pointer_cast<Type>($4);
auto valueMetadata = dynamic_pointer_cast<StringListTok>($6);
auto valueMetadata = dynamic_pointer_cast<MetadataListTok>($6);
auto valueType = dynamic_pointer_cast<Type>($7);
ContainerPtr cont = currentUnit->currentContainer();
$$ = cont->createDictionary(ident->v, keyType, keyMetadata->v, valueType, valueMetadata->v);
}
| ICE_DICTIONARY '<' metadata type ',' metadata type '>' keyword
{
auto ident = dynamic_pointer_cast<StringTok>($9);
auto keyMetadata = dynamic_pointer_cast<StringListTok>($3);
auto keyMetadata = dynamic_pointer_cast<MetadataListTok>($3);
auto keyType = dynamic_pointer_cast<Type>($4);
auto valueMetadata = dynamic_pointer_cast<StringListTok>($6);
auto valueMetadata = dynamic_pointer_cast<MetadataListTok>($6);
auto valueType = dynamic_pointer_cast<Type>($7);
ContainerPtr cont = currentUnit->currentContainer();
$$ = cont->createDictionary(ident->v, keyType, keyMetadata->v, valueType, valueMetadata->v); // Dummy
Expand Down Expand Up @@ -1646,7 +1646,7 @@ enumerator_list
// ----------------------------------------------------------------------
: metadata enumerator ',' enumerator_list
{
auto metadata = dynamic_pointer_cast<StringListTok>($1);
auto metadata = dynamic_pointer_cast<MetadataListTok>($1);
auto enumerator = dynamic_pointer_cast<Enumerator>($2);
if (enumerator && !metadata->v.empty())
{
Expand All @@ -1658,7 +1658,7 @@ enumerator_list
}
| metadata enumerator
{
auto metadata = dynamic_pointer_cast<StringListTok>($1);
auto metadata = dynamic_pointer_cast<MetadataListTok>($1);
auto enumerator = dynamic_pointer_cast<Enumerator>($2);
if (enumerator && !metadata->v.empty())
{
Expand Down Expand Up @@ -1787,7 +1787,7 @@ parameters
{
ParamDeclPtr pd = op->createParamDecl(tsp->name, tsp->type, isOutParam->v, tsp->isOptional, tsp->tag);
currentUnit->currentContainer()->checkIntroduced(tsp->name, pd);
auto metadata = dynamic_pointer_cast<StringListTok>($2);
auto metadata = dynamic_pointer_cast<MetadataListTok>($2);
if (!metadata->v.empty())
{
pd->setMetadata(metadata->v);
Expand All @@ -1803,7 +1803,7 @@ parameters
{
ParamDeclPtr pd = op->createParamDecl(tsp->name, tsp->type, isOutParam->v, tsp->isOptional, tsp->tag);
currentUnit->currentContainer()->checkIntroduced(tsp->name, pd);
auto metadata = dynamic_pointer_cast<StringListTok>($4);
auto metadata = dynamic_pointer_cast<MetadataListTok>($4);
if (!metadata->v.empty())
{
pd->setMetadata(metadata->v);
Expand Down Expand Up @@ -1987,21 +1987,27 @@ string_literal
;

// ----------------------------------------------------------------------
string_list
metadata_list
// ----------------------------------------------------------------------
: string_list ',' string_literal
: metadata_list ',' string_literal
{
auto str = dynamic_pointer_cast<StringTok>($3);
auto stringList = dynamic_pointer_cast<StringListTok>($1);
stringList->v.push_back(str->v);
$$ = stringList;
auto metadataList = dynamic_pointer_cast<MetadataListTok>($1);

auto metadata = make_shared<Metadata>(str->v, currentUnit->currentFile(), currentUnit->currentLine());
metadataList->v.push_back(metadata);

$$ = metadataList;
}
| string_literal
{
auto str = dynamic_pointer_cast<StringTok>($1);
auto stringList = make_shared<StringListTok>();
stringList->v.push_back(str->v);
$$ = stringList;
auto metadataList = make_shared<MetadataListTok>();

auto metadata = make_shared<Metadata>(str->v, currentUnit->currentFile(), currentUnit->currentLine());
metadataList->v.push_back(metadata);

$$ = metadataList;
}
;

Expand Down Expand Up @@ -2089,7 +2095,7 @@ const_def
// ----------------------------------------------------------------------
: ICE_CONST metadata type ICE_IDENTIFIER '=' const_initializer
{
auto metadata = dynamic_pointer_cast<StringListTok>($2);
auto metadata = dynamic_pointer_cast<MetadataListTok>($2);
auto const_type = dynamic_pointer_cast<Type>($3);
auto ident = dynamic_pointer_cast<StringTok>($4);
auto value = dynamic_pointer_cast<ConstDefTok>($6);
Expand All @@ -2098,7 +2104,7 @@ const_def
}
| ICE_CONST metadata type '=' const_initializer
{
auto metadata = dynamic_pointer_cast<StringListTok>($2);
auto metadata = dynamic_pointer_cast<MetadataListTok>($2);
auto const_type = dynamic_pointer_cast<Type>($3);
auto value = dynamic_pointer_cast<ConstDefTok>($5);
currentUnit->error("missing constant name");
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/Slice/GrammarUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace Slice
std::string literal;
};

struct StringListTok final : public GrammarBase
struct MetadataListTok final : public GrammarBase
{
StringListTok() {}
StringList v;
MetadataListTok() {}
MetadataList v;
};

struct TypeStringTok final : public GrammarBase
Expand Down
Loading
Loading