Commit 504d6197 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

added a representation for projection constructors, using the existing...

added a representation for projection constructors, using the existing projections, parser should work
parent aaf5cf18
......@@ -273,7 +273,7 @@ const char* FPParameter::identifier()
Parameter::Parameter()
{
this->type_ = null;
this->type_ = 0x0;
this->name_ = "";
}
......
......@@ -14,8 +14,6 @@ class TypeNameVisitor;
class AllocateTypeVisitor;
class Variable;
enum PrimType {pt_char_t, pt_short_t, pt_int_t, pt_long_t, pt_longlong_t, pt_capability_t};
enum type_k {};
......@@ -37,6 +35,7 @@ class LexicalScope : public Base
public:
LexicalScope();
LexicalScope(LexicalScope *outer_scope);
virtual std::vector<Rpc*> rpc_in_scope();
virtual bool insert(Rpc *r);
virtual Type* lookup(const char *sym, int* err);
virtual bool insert(const char *sym, Type* type);
......@@ -56,6 +55,7 @@ class GlobalScope : public LexicalScope
public:
GlobalScope();
virtual std::vector<Rpc*> rpc_in_scope();
virtual bool insert(Rpc *r);
virtual Type* lookup(const char *symbol, int *err);
virtual bool insert(const char *symbol, Type *type);
......@@ -79,7 +79,6 @@ class Type : public Base
class Variable : public Base
{
public:
// virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data) = 0;
virtual Type* type() = 0;
virtual const char* identifier() = 0;
virtual void set_accessor(Variable *v) = 0;
......@@ -88,6 +87,53 @@ class Variable : public Base
virtual Rpc* scope() = 0;
};
class GlobalVariable : public Variable
{
public:
GlobalVariable(Type *type, const char *id);
virtual Type* type() = 0;
virtual const char* identifier() = 0;
};
class Parameter : public Variable
{
Type* type_;
const char* name_;
Marshal_type *marshal_info_;
bool in_;
bool out_;
bool alloc_;
bool bind_;
Variable *accessor_;
Rpc *function_;
public:
Parameter();
Parameter(Type* type, const char* name);
~Parameter();
// virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual Type* type();
virtual Rpc* scope();
void set_marshal_info(Marshal_type* mt); // ??????????????????????????????
Marshal_type* marshal_info(); //???????????????????????????????????
virtual const char* identifier();
virtual void set_accessor(Variable *v);
virtual bool bind();
virtual bool alloc();
virtual bool in();
virtual bool out();
virtual Variable* accessor();
};
class FPParameter : public Parameter
{
Type *type_;
public:
FPParameter(Type *type);
virtual Type* type();
virtual const char* identifier();
};
class FunctionPointer : public Type
{
const char *identifier_;
......@@ -190,8 +236,9 @@ class ProjectionType : public Type // complex type
const char* id_;
const char* real_type_;
std::vector<ProjectionField*> fields_;
std::vector<GlobalVariable*> init_variables_;
public:
ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields, std::vector<GlobalVariable*> init_variables);
ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields);
// virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual CCSTTypeName* accept(TypeNameVisitor *worker);
......@@ -204,43 +251,6 @@ class ProjectionType : public Type // complex type
~ProjectionType(){printf("projection type destructor\n");}
};
class Parameter : public Variable
{
Type* type_;
const char* name_;
Marshal_type *marshal_info_;
bool in_;
bool out_;
bool alloc_;
bool bind_;
Variable *accessor_;
Rpc *function_;
public:
Parameter();
Parameter(Type* type, const char* name);
~Parameter();
// virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual Type* type();
virtual Rpc* scope();
void set_marshal_info(Marshal_type* mt); // ??????????????????????????????
Marshal_type* marshal_info(); //???????????????????????????????????
virtual const char* identifier();
virtual void set_accessor(Variable *v);
virtual bool bind();
virtual bool alloc();
virtual bool in();
virtual bool out();
virtual Variable* accessor();
};
class FPParameter : public Parameter
{
Type *type_;
public:
FPParameter(Type *type);
};
class ReturnVariable : public Variable
{
const char* name_; // to be decided by a name space or something
......@@ -307,9 +317,10 @@ class Rpc : public Base
class Module : public Base
{
// const char *verbatim_;
LexicalScope *module_scope_;
std::vector<GlobalVariable*> globals_;
std::vector<Rpc*> rpc_definitions_;
public:
Module(LexicalScope* scope);
Module(std::vector<Rpc*> rpc_definitions, std::vector<GlobalVariable*> globals);
std::vector<Rpc*> rpc_definitions();
};
......@@ -330,6 +341,7 @@ class TypeNameVisitor // generates CCSTTypeName for each type.
CCSTTypeName* visit(IntegerType *it);
CCSTTypeName* visit(PointerType *pt);
CCSTTypeName* visit(ProjectionType *pt);
CCSTTypeName* visit(FunctionPointer *fp);
};
class AllocateTypeVisitor
......@@ -348,8 +360,7 @@ class AllocateTypeVisitor
CCSTStatement* visit(IntegerType *it, Variable *v);
CCSTStatement* visit(PointerType *pt, Variable *v);
CCSTStatement* visit(ProjectionType *pt, Variable *v);
CCSTStatement* visit(FunctionPointer *fp, Variable *v);
};
class AllocateVariableVisitor
......
......@@ -179,23 +179,38 @@ IdentStart = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
IdentCont = IdentStart | [0123456789]
unnamed_scope = Spacing OPENC Spacing s:UnnamedScopeDefinitions Rpc* Spacing CLOSEC Spacing {{
// rpc adds itself to scope.
value = s;
}}
pc_unnamed_scope= Spacing OPENC Spacing s:UnnamedScopeDefinitions p:ProjField* Spacing CLOSEC Spacing {{
pc_unnamed_scope= Spacing OPENC Spacing s:UnnamedScopeDefinitions p:ProjField* Spacing CLOSEC Spacing {{
std::vector<ProjectionField*> *fields = new std::vector<ProjectionField*>();
for(Value::iterator it = p.getValues().begin(); it != p.getValues().end(); it ++) {
const Value & v = *it;
std::vector<ProjectionField*> *pf = (std::<ProjectionField*>*) v.getValue();
fields->insert(fields->end(), pf->begin(), pf->end());
}
value = fields;
}}
Interface = "interface" Space+ id:Identifier Spacing OPEN globals:Parameters Spacing CLOSE Spacing OPENC Spacing s:ModuleScopeDefinitions Rpc* us:unnamed_scope* Spacing CLOSEC Spacing {{
Interface = "interface" Space+ id:Identifier Spacing OPEN globals:Globals Spacing CLOSE Spacing OPENC Spacing s:ModuleScopeDefinitions r:Rpc* us:unnamed_scope* Spacing CLOSEC Spacing {{
LexicalScope *module_scope = (LexicalScope*) s.getValue();
std::vector<Rpc*> rpcs;
std::vector<GlobalVariable*> globals = (std::vector<GlobalVariable*>) *globals.getValue();
for(Value::iterator it = r.getValues().begin(); it != r.getValues().end(); it ++) {
const Value & v2 = *it;
Rpc *r2 = (Rpc*) v2.getValue();
rpcs.push_back(r2);
}
for(Value::iterator it = us.getValues().begin(); it != us.getValues().end(); it ++) {
const Value & v2 = *it;
LexicalScope *ls = (LexicalScope*) v2.getValue();
module_scope->add_inner_scope(ls);
// module_scope->add_inner_scope(ls);
std::vector<Rpc*> rtemp = ls->rpc_in_scope();
rpcs.insert(rpcs.end(), rtemp.begin(), rtemp.end());
}
value = new Module(module_scope);
value = new Module(rpcs, globals);
}}
Typedef = "typedef" Spacing "<" Spacing rt:RealType Spacing "," Spacing mt:Type_form ">" Spacing id:Identifier Spacing {{
......@@ -316,6 +331,25 @@ Parameters = f:FirstParam* l:LastParam {{
value = params;
}}
FirstGlobal = t:Type_form id:Identifier Spacing COMMA Spacing {{
value = new GlobalVariable((Type*) t.getValue(), (char*) id.getValue());
}}
LastGlobal = t:Type_form id:Identifier Spacing {{
value = new GlobalVariable((Type*) t.getValue(), (char*) id.getValue());
}}
Globals = f:FirstGlobal* l:LastGlobal {{
std::vector<GlobalVariable*> *globals = new std::vector<GlobalVariable*>();
for(Value::iterator it = f.getValues().begin(); it != f.getValues().end(); it ++) {
const Value & v = *it;
GlobalVariable *gv = (GlobalVariable*) v.getValue();
globals->push_back(gv);
}
globals->push_back((GlobalVariable*) l.getValue());
value = globals;
}}
FP_Parameters = f:FP_FirstParam* l:FP_LastParam {{
std::vector<FPParameter* > *params = new std::vector<FPParameter*>();
for(Value::iterator it = f.getValues().begin(); it != f.getValues().end(); it ++) {
......@@ -343,18 +377,28 @@ Rpc = "rpc" Space+ t:Type_form id1:Identifier Spacing OPEN p:Parameters CLOSE S
Globals =
Projection_constructor = "projection" Space+ id:Identifier Spacing "<" Spacing t:Proj_type ">" Spacing OPEN Spacing g:Globals Spacing CLOSE Spacing OPENC Spacing s:ProjectionScopeDefinitions p:ProjField* us:unnamed_scope* Spacing CLOSEC Spacing {{
...
std::vector<ProjectionField*> fields;
std::vector<GlobalVariable*> globals = (std::vector<GlobalVariable*>) *g.getValue();
for(Value::iterator it = p.getValues().begin(); it != p.getValues().end(); it ++) {
const Value & v = *it;
std::vector<ProjectionField*> tmp = (std::vector<ProjectionField*>) *v.getValue();
fields.insert(fields.end(), tmp.begin(), tmp.end());
}
ProjectionType *val = new ProjectionType((char*) id.getValue(), (char*) t.getValue(), fields, globals);
insertType((char*) id.getValue(), val);
value = val;
}}
Projection = "projection" Space+ id:Identifier Spacing "<" Spacing t:Proj_type ">" Spacing OPENC Spacing p:ProjField* CLOSEC Spacing {{
std::vector<ProjectionField *> p_fields;
std::vector<ProjectionField *> fields;
for(Value::iterator it = p.getValues().begin(); it != p.getValues().end(); it ++)
{
const Value & v = *it;
ProjectionField * p2 = (ProjectionField *) v.getValue();
p_fields.push_back(p2);
std::vector<ProjectionField*> tmp = (std::vector<ProjectionField*>) *v.getValue();
fields.insert(fields.end(), tmp.begin(), tmp.end());
}
ProjectionType * val = new ProjectionType((char* ) id.getValue(), (char* ) t.getValue(), p_fields);
ProjectionType * val = new ProjectionType((char* ) id.getValue(), (char*) t.getValue(), fields);
insertType((char*)id.getValue(), val);
value = val;
}}
......@@ -399,9 +443,7 @@ Specification = s:Start* l:Last {{
ProjField = t:Type_form Spacing OPENS Spacing s:Specification CLOSES Spacing id:Identifier Spacing SEMI Spacing {{
bool in = false; bool out = false; bool bind = false; bool alloc = false;
std::vector<bool>* specs = (std::vector<bool>*) s.getValue();
printf("In Proj field\n");
int i = 0;
printf("%zu", specs->size());
if(specs->at(0) == true) {
out = true;
......@@ -416,8 +458,9 @@ ProjField = t:Type_form Spacing OPENS Spacing s:Specification CLOSES Spacing id:
alloc = true;
}
printf("about to construct projection field\n");
value = new ProjectionField(in, out, alloc, bind, (Type *) t.getValue(), (char *) id.getValue());
std::vector<ProjectionField*> *fields = new std::vector<ProjectionField*>();
fields->push_back(new ProjectionField(in, out, alloc, bind, (Type *) t.getValue(), (char *) id.getValue()))
value = fields;
}}
| "rpc" Space+ rt:Type_form Spacing OPENS Spacing s:Specification CLOSES Spacing OPEN Spacing "*" Spacing id:Identifier CLOSE Spacing OPEN p:FP_Parameters CLOSE SEMI Spacing {{
......@@ -441,8 +484,11 @@ ProjField = t:Type_form Spacing OPENS Spacing s:Specification CLOSES Spacing id:
}
FunctionPointer *fp = new FunctionPointer((char*) id.getValue(), (Type*) rt.getValue(), (std::vector<FPParameter*>) *p.getValue());
value = new ProjectionField(in, out, alloc, bind, fp, (char*) id.getValue());
std::vector<ProjectionField*> *fields = new std::vector<ProjectionField*>();
fields->push_back(new ProjectionField(in, out, alloc, bind, fp, (char*) id.getValue()));
value = fields;
}}
| pc_unnamed_scope
Last = k:Keyword Spacing {{ value = k; }}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment