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

Allow annotations on functions #4452

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion frontends/parsers/p4/p4parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,11 @@ initializer
/**************** Expressions ****************/

functionDeclaration
: functionPrototype blockStatement {
: annotations functionPrototype blockStatement {
auto ann = new IR::Annotations(@1, *$1);
driver.structure->pop();
$$ = new IR::Function($2->srcInfo, $2->name, ann, $2->type, $3); }
| functionPrototype blockStatement {
driver.structure->pop();
$$ = new IR::Function($1->srcInfo, $1->name, $1->type, $2); }
;
Expand Down
4 changes: 3 additions & 1 deletion ir/ir.def
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ class SwitchStatement : Statement {
split.run_visit(); }
}

class Function : Declaration, IFunctional, ISimpleNamespace, INestedNamespace {
class Function : Declaration, IFunctional, IAnnotated, ISimpleNamespace, INestedNamespace {
optional Annotations annotations = Annotations::empty;
Type_Method type;
BlockStatement body;
ParameterList getParameters() const override {
Expand All @@ -512,6 +513,7 @@ class Function : Declaration, IFunctional, ISimpleNamespace, INestedNamespace {
return type->parameters->getDeclByName(name); }
std::vector<INamespace> getNestedNamespaces() const override {
return { type->typeParameters }; }
Annotations getAnnotations() const override { return annotations; }
}

/////////////////////////////////////////////////////////////
Expand Down
Loading