Skip to content

Commit

Permalink
Allow annotations on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDodd committed Mar 6, 2024
1 parent d8c3f42 commit 2b206bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 2b206bd

Please sign in to comment.