Commit e2ddc9fa authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

just added syntax support for typedef

parent e775c983
......@@ -6,29 +6,29 @@ PrimitiveType::PrimitiveType(TypeModifier type_mod, PrimType primitive)
this->primitive_ = primitive;
}
ProjectionType::ProjectionType(char * type_name, bool pointer)
ProjectionType::ProjectionType(char* type_name, bool pointer)
{
this->type_name_ = type_name;
this->pointer_ = pointer;
}
Scope::Scope(char* verbatim, std::vector<Rpc* >* rpc_definitions, std::vector<Message* >* message_definitions,
std::map<char* , Projection* >* projection_definitions)
std::map<char* , Definition* >* symbol_table)
{
this->verbatim_ = verbatim;
this->rpc_definitions_ = rpc_definitions;
this->message_definitions_ = message_definitions;
this->projection_definitions_ = projection_definitions;
this->symbol_table__ = symbol_table;
}
Rpc::Rpc(Type* return_type, char * name, std::vector<Parameter* >* parameters)
Rpc::Rpc(Type* return_type, char* name, std::vector<Parameter* >* parameters)
{
this->return_type_ = return_type;
this->name_ = name;
this->parameters_ = parameters;
}
Projection::Projection(char * name, char* true_type, std::vector<ProjectionField* >* fields)
Projection::Projection(char* name, char* true_type, std::vector<ProjectionField* >* fields)
{
this->name_ = name;
this->true_type_ = true_type;
......@@ -51,18 +51,24 @@ Parameter::Parameter(Type* type, char* name)
this->name_ = name;
}
MessageField::MessageField(Type* field_type, char * field_name)
MessageField::MessageField(Type* field_type, char* field_name)
{
this->field_type_ = field_type;
this->field_name_ = field_name;
}
Message::Message(char * name, std::vector<MessageField* >* fields)
Message::Message(char* name, std::vector<MessageField* >* fields)
{
this->name_ = name;
this->fields_ = fields;
}
Typedef::Typedef(char* real_type, Type* marshal_type, char* typedef_name)
{
this->real_type_ = real_type;
this->marshal_type_ = marshal_type;
this->name_ = typedef_name;
}
......@@ -4,7 +4,7 @@
#include <vector>
#include <map>
enum DefinitionType {kRpc = 1, kModule, kMessage, kProjection};
enum DefinitionType {kRpc = 1, kModule, kMessage, kProjection, kTypedef};
enum PrimType { kChar = 1, kShort, kInt, kLong, kLongLong, kCapability};
enum TypeModifier {kUnsigned = 1, kNone};
......@@ -47,6 +47,18 @@ class ProjectionType : public Type // complex type
// get full name function? class isn't aware of parent need to pass env
};
class Typedef : public Definition
{
char* real_type_; // how should this be represented?
Type* marshal_type_; // should this be a supported type?
char* name_;
public:
Typedef(char* real_type, Type* marshal_type, char* typedef_name);
char* name() { return name_; }
DefinitionType get_definition_type(){ return kTypedef; }
};
class Parameter
{
Type* type_;
......@@ -126,12 +138,12 @@ class Scope
char* verbatim_;
std::vector<Rpc *>* rpc_definitions_;
std::vector<Message *>* message_definitions_;
std::map<char *, Projection *>* projection_definitions_;
std::map<char *, Definition *>* symbol_table__;
// believe it is only necessary to store projections in "env" since functions can't be referenced in other functions
public:
Scope(char* verbatim, std::vector<Rpc* >* rpc_definitions, std::vector<Message* >* message_definitions,
std::map<char* , Projection* >* projection_definitions);
std::map<char* , Definition* >* symbol_table);
};
......
......@@ -26,10 +26,10 @@ IdentStart = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
IdentCont = IdentStart | [0123456789]
File = Spacing v:Verbatim t:Things* <eof> {{ std::vector<Definition *>* defs = new std::vector<Definition *>;
File = Spacing v:Verbatim? t:Things* <eof> {{ std::vector<Definition *>* defs = new std::vector<Definition *>;
std::vector<Rpc *>* rpcs = new std::vector<Rpc *>;
std::vector<Message *>* messages = new std::vector<Message *>;
std::map<char *, Projection *> *env = new std::map<char *, Projection *>;
std::map<char *, Definition*> *env = new std::map<char *, Definition *>;
for(Value::iterator it = t.getValues().begin(); it != t.getValues().end(); it ++)
{
const Value & v = *it;
......@@ -56,7 +56,12 @@ File = Spacing v:Verbatim t:Things* <eof> {{ std::vector<Definition *>* defs =
case kProjection:
{
Projection* proj = reinterpret_cast<Projection *>(ds);
env->insert(std::pair<char *, Projection *>(proj->name(), proj));
env->insert(std::pair<char *, Definition *>(proj->name(), ds));
}
case kTypedef:
{
Typedef* td = reinterpret_cast<Typedef*>(ds);
env->insert(std::pair<char*, Definition*>(td->name(), ds));
}
break;
default:
......@@ -68,7 +73,10 @@ File = Spacing v:Verbatim t:Things* <eof> {{ std::vector<Definition *>* defs =
}
value = new Scope((char*) v.getValue(), rpcs, messages, env); }}
Verbatim = "verbatim" Spacing "[" contents:VerbatimContent "]" {{ std::ostringstream total;
Typedef = "typedef" Spacing "<" Spacing rt:RealType Spacing "," Spacing mt:Type Spacing ">" Spacing id:Identifier Spacing {{
value = new Typedef((char*) rt.getValue(), (Type*) mt.getValue(), (char*) id.getValue());}}
Verbatim = "verbatim" Spacing "[" contents:VerbatimContent "]" {{ std::ostringstream total;
for(Value::iterator it = contents.getValues().begin(); it != contents.getValues().end(); it ++)
{
const Value &v = *it;
......@@ -78,7 +86,14 @@ Verbatim = "verbatim" Spacing "[" contents:VerbatimContent "]" {{ std::ostringst
std::string str = total.str();
value = &str[0]; }}
VerbatimContent = !"]" .
VerbatimContent = !"]" .
RealType = fp:Identifier? Spacing sp:Identifier {{ //temporary solution
std::ostringstream total;
total << fp.getValue() << ' ' << sp.getValue();
std::string str = total.str();
value = &str[0];
}}
String = <ascii 34> l:any_letter+ <ascii 34> {{
std::ostringstream total;
......@@ -116,7 +131,7 @@ String = <ascii 34> l:any_letter+ <ascii 34> {{
any_letter = [_.,/?<>'; =:%`!@#$^&*()-+{}|\\ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]
Things = Rpc | Message | Projection
Things = Typedef | Rpc | Message | Projection
Include = "#include" Space+ "<" Spacing f:Identifier Spacing ">" Spacing {{
std::ostringstream total;
......
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