Skip to content

Commit

Permalink
Fix bug p4lang#108
Browse files Browse the repository at this point in the history
- Allow TYPE as name in typeParameterLists
- Remove optional type params from ctor decl
  • Loading branch information
Chris Dodd committed Oct 19, 2016
1 parent 772ad28 commit 74f005c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions backends/p4test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ P14BUGS = \
XFAIL_TESTS += \
$(P14BUGS) \
p4/testdata/p4_16_samples/cast-call.p4.test

# see discussion in issue #108
XFAIL_TESTS += p4/testdata/p4_16_errors/generic_e.p4.test
18 changes: 8 additions & 10 deletions frontends/p4/p4-parse.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,16 @@ functionPrototype
'(' parameterList ')' { structure.pop(); }
{ auto params = new IR::ParameterList(@6, $6);
auto mt = new IR::Type_Method(@2, $3, $1, params);
$$ = new IR::Method(@2, *$2, mt, false); }
$$ = new IR::Method(@2, *$2, mt); }
;

methodPrototype
: functionPrototype ';' { $$ = $1; }
| ABSTRACT functionPrototype ';' { $$ = $2; $$->setAbstract(); }
| TYPE optTypeParameters { structure.pushNamespace("", @1, false);
structure.declareTypes($2->parameters); } // constructor
'(' parameterList ')' ';' { structure.pop(); }
{ auto par = new IR::ParameterList(@5, $5);
auto mt = new IR::Type_Method(@1, $2, nullptr, par);
$$ = new IR::Method(@1, IR::ID(@1, $1), mt, false); }
| ABSTRACT functionPrototype ';' { $$ = $2; $$->setAbstract(); }
| TYPE '(' parameterList ')' ';' // constructor
{ auto par = new IR::ParameterList(@3, $3);
auto mt = new IR::Type_Method(@1, par);
$$ = new IR::Method(@1, IR::ID(@1, $1), mt); }
;

/************************** TYPES ****************************/
Expand Down Expand Up @@ -586,9 +584,9 @@ optTypeParameters
;

typeParameterList
: nonTypeName { $$ = new IR::IndexedVector<IR::Type_Var>();
: name { $$ = new IR::IndexedVector<IR::Type_Var>();
$$->push_back(new IR::Type_Var(@1, *$1)); }
| typeParameterList ',' nonTypeName { ($$=$1)->push_back(new IR::Type_Var(@3, *$3)); }
| typeParameterList ',' name { ($$=$1)->push_back(new IR::Type_Var(@3, *$3)); }
;

typeArg
Expand Down
8 changes: 5 additions & 3 deletions ir/type.def
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,10 @@ class Type_ActionEnum : Type {
}

abstract Type_MethodBase : Type, IMayBeGenericType {
TypeParameters typeParameters; // we generally want these visited first
NullOK Type returnType; // nullptr for constructors or functors; nullptr is not void
optional TypeParameters typeParameters = new TypeParameters();
// we generally want these visited first
optional NullOK Type returnType = nullptr;
// nullptr for constructors or functors; nullptr is not void
ParameterList parameters;

size_t getParameterCount() const { return parameters->size(); }
Expand Down Expand Up @@ -438,7 +440,7 @@ class Type_Action : Type_MethodBase {

class Method : Declaration {
Type_Method type;
bool isAbstract;
optional bool isAbstract = false;
size_t getParameterCount() const { return type->getParameterCount(); }
void setAbstract() { isAbstract = true; }
}
Expand Down
1 change: 1 addition & 0 deletions tools/ir-generator/ir-generator.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ expression
: name | STRING | INTEGER | ZERO
| expression '(' ')' { $$ = $1 + "()"; }
| expression '+' '+' { $$ = $1 + "++"; }
| NEW name { $$ = "new " + $2; }
;

name: IDENTIFIER | name DBLCOL IDENTIFIER { $$ = $1 + "::" + $3; }
Expand Down

0 comments on commit 74f005c

Please sign in to comment.