Commit 8c62f176 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

can now generate a header file from the simple interface and message idl...

can now generate a header file from the simple interface and message idl format, fixed bugs with char * in grammar
parent e51d81aa
all: compiler
compiler: flounder_parser.o idl_compiler.o ast.o
g++ flounder_parser.o idl_compiler.o ast.o -o compiler
compiler: flounder_parser.o idl_compiler.o ast.o visitor.o
g++ flounder_parser.o visitor.o idl_compiler.o ast.o -o compiler
idl_compiler.o: idl_compiler.cpp flounder_parser.h
g++ -c -g idl_compiler.cpp flounder_parser.h
......@@ -10,6 +10,9 @@ idl_compiler.o: idl_compiler.cpp flounder_parser.h
ast.o: ast.cpp ast.h
g++ -c -g ast.cpp ast.h
visitor.o: visitor.cpp visitor.h
g++ -c -g visitor.cpp visitor.h
flounder_parser.o: flounder_parser.cpp flounder_parser.h
g++ -c -g flounder_parser.cpp flounder_parser.h
......
......@@ -14,19 +14,30 @@ Interface::Interface(char * n, std::vector<Message*> * m)
description = 0;
function_decs = m;
}
std::vector<Message*> *Interface::getMessages()
{
return this->function_decs;
}
Message::Message(char * n, std::vector<Argument*> * a)
{
name = n;
args = a;
this->name = n;
this->args = a;
}
char * Message::getName()
{
return this->name;
}
std::vector<Argument*> *Message::getArguments()
{
return this->args;
}
Argument::Argument(Type * t_, char * n, char * s)
{
......@@ -44,7 +55,33 @@ Argument::Argument(Type * t_, char * n)
size = 0;
}
Type::Type()
bool Argument::isDynamic()
{
return this->array;
}
Type * Argument::getType()
{
return this->t;
}
char * Argument::getName()
{
return this->name;
}
char * Argument::getSize()
{
return this->size;
}
Type::Type(char * t)
{
this->t = t;
}
char * Type::getStr()
{
return this->t;
}
......@@ -6,8 +6,10 @@
class Type
{
char * t;
public:
Type();
Type(char * t);
char * getStr();
};
class Argument
......@@ -19,6 +21,12 @@ class Argument
public:
Argument(Type * t, char * n, char * s);
Argument(Type * t, char *n);
bool isDynamic();
Type * getType();
char * getName();
char * getSize();
};
class Message
......@@ -27,6 +35,8 @@ class Message
std::vector<Argument*> * args;
public:
Message(char * n, std::vector<Argument* > * a);
char * getName();
std::vector<Argument*> * getArguments();
};
......@@ -38,6 +48,7 @@ class Interface
public:
Interface(char * n, char * desc, std::vector<Message*> * m);
Interface(char * n, std::vector<Message*> * m);
std::vector<Message*> * getMessages();
};
......
......@@ -3,7 +3,8 @@ options: debug9
include: {{ #include "ast.h"
#include <vector>
#include <stdlib.h> }}
#include <stdlib.h>
#include <string> }}
code: {{
void cast_m(std::vector<Message* > * v, Value & val)
{
......@@ -36,9 +37,8 @@ Interface = INTERFACE n:Identifier OPENC Spacing m:Message+ CLOSEC SEMI {{ std::
value = new Interface((char *)n.getValue(),(char *)d.getValue(), functions); }}
Message = MESSAGE i:Identifier OPEN a:Arguments CLOSE SEMI Spacing {{ std::vector<Argument*> * args = new std::vector<Argument*>;
cast_a(args, a);
value = new Message((char*)i.getValue(), args); }}
Message = MESSAGE i:Identifier OPEN a:Arguments CLOSE SEMI Spacing {{
value = new Message((char*)i.getValue(), (std::vector<Argument*> *) a.getValue()); }}
Arguments = a:ArgStart* a2:ArgLast {{ std::vector<Argument*> * args = new std::vector<Argument*>;
cast_a(args, a);
......@@ -52,9 +52,13 @@ ArgStart = s:SimpleArg COMMA Spacing {{ value = s; }}
ArgLast = s:SimpleArg Spacing {{ value = s; }}
| d:DynamicArg Spacing {{ value = d; }}
SimpleArg = t:Identifier i:Identifier {{ value = new Argument((Type*) t.getValue(), (char *) i.getValue()); }}
SimpleArg = t:Identifier i:Identifier {{
Type * ty = new Type((char *) t.getValue());
value = new Argument(ty, (char *) i.getValue()); }}
DynamicArg = t:Identifier i:Identifier OPENS i2:Identifier CLOSES {{ value = new Argument((Type*) t.getValue(), (char *) i.getValue(), (char *) i2.getValue()); }}
DynamicArg = t:Identifier i:Identifier OPENS i2:Identifier CLOSES {{
Type * ty = new Type((char *) t.getValue());
value = new Argument(ty, (char *) i.getValue(), (char *) i2.getValue()); }}
Type = "bool" | "int32" | "char"
......@@ -62,14 +66,27 @@ Type = "bool" | "int32" | "char"
Description = """ d:.* """ Spacing
Identifier = i1:IdentStart i2:IdentCont* Spacing
Identifier = i1:IdentStart i2:IdentCont* Spacing {{
char * str = (char *) malloc(sizeof(char)*(2+ i2.getValues().size()));
char * temp1 = (char *) malloc(sizeof(char)*2);
temp1[0] = (char) (intptr_t) i1.getValue();
temp1[1] = '\0';
strcpy(str, temp1);
for(Value::iterator it = i2.getValues().begin(); it != i2.getValues().end(); it ++)
{
const Value & v = *it;
char letter = (char) (intptr_t) v.getValue();
char * temp2 = (char *) malloc(sizeof(char)*2);
temp2[0] = letter;
temp2[1] = '\0';
strcat(str, temp2);
}
value = str; }}
IdentStart = i:[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_] {{
value = i; }}
IdentCont = i:IdentStart {{
value = i; }}
| i:[0123456789] {{
value = i; }}
IdentStart = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
IdentCont = IdentStart
| [0123456789]
......
#include "ast.h"
#include "flounder_parser.h"
#include "visitor.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
int main(int argc, char ** argv)
{
if(argc < 2)
if(argc != 4)
{
printf("Must provide a filename.");
printf("Command line must be of form: -option in_file out_file\n");
exit(0);
}
try
{
printf("getting filename");
char * filename = argv[1];
printf("%s",filename);
Interface * tree = (Interface *) Parser::parse(std::string(filename));
printf("testing");
char * option = argv[1];
char * in_file = argv[2];
char * out_file = argv[3];
if(strstr(option,"-header"))
{
FILE * out;
Interface * tree = (Interface *) Parser::parse(std::string(in_file));
printf("we have a tree\n");
out = fopen(out_file, "w");
printf("we have opened a file\n");
generate_header_file(tree, out);
}
else if(strstr(option,"-stub"))
{
FILE * out;
Interface * tree = (Interface *) Parser::parse(std::string(in_file));
out = fopen(out_file, "w");
generate_stub_file(tree, out);
}
else
printf("not a valid option: %s\n", option);
exit(0);
}
catch (const Parser::ParseException &e)
{
printf("caught an exception");
printf("caught an exception\n");
std::cout << e.getReason();
}
......
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