[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: treecc gen_ruby.c,1.1,1.2 stream.h,1.2,1.3 st
From: |
Peter Minten <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: treecc gen_ruby.c,1.1,1.2 stream.h,1.2,1.3 stream.c,1.2,1.3 ChangeLog,1.49,1.50 |
Date: |
Sat, 09 Nov 2002 06:36:28 -0500 |
Update of /cvsroot/dotgnu-pnet/treecc
In directory subversions:/tmp/cvs-serv18088
Modified Files:
gen_ruby.c stream.h stream.c ChangeLog
Log Message:
Worked on Ruby support.
Index: gen_ruby.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/treecc/gen_ruby.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** gen_ruby.c 2 Nov 2002 04:38:21 -0000 1.1
--- gen_ruby.c 9 Nov 2002 11:36:26 -0000 1.2
***************
*** 42,46 ****
TreeCCStream *stream = node->source;
TreeCCNode *child;
! TreeCCStreamPrint(stream, "class %s\n", node->name);
child = node->firstChild;
while(child != 0)
--- 42,46 ----
TreeCCStream *stream = node->source;
TreeCCNode *child;
! TreeCCStreamPrint(stream, "class %s \n", node->name);
child = node->firstChild;
while(child != 0)
***************
*** 48,53 ****
if((child->flags & TREECC_NODE_ENUM_VALUE) != 0)
{
! TreeCCStreamPrint(stream, "\t%s = %i,\n",
child->name, counter++);
}
child = child->nextSibling;
}
--- 48,54 ----
if((child->flags & TREECC_NODE_ENUM_VALUE) != 0)
{
! TreeCCStreamPrint(stream, " %s = %i\n",
child->name, counter++);
}
+
child = child->nextSibling;
}
***************
*** 165,169 ****
if(node == actualNode)
{
! TreeCCStreamPrint(stream, "\tdef %s(",
virt->name);
}
else
--- 166,170 ----
if(node == actualNode)
{
! TreeCCStreamPrint(stream, " def %s(",
virt->name);
}
else
***************
*** 178,186 ****
if(node == actualNode)
{
! TreeCCStreamPrint(stream, "\tdef %s(",
virt->name);
}
else
{
! TreeCCStreamPrint(stream, "\tdef %s(",
virt->name);
}
}
--- 179,187 ----
if(node == actualNode)
{
! TreeCCStreamPrint(stream, " def %s(",
virt->name);
}
else
{
! TreeCCStreamPrint(stream, " def %s(",
virt->name);
}
}
***************
*** 224,228 ****
TreeCCStreamLine(stream, operCase->codeLinenum,
operCase->codeFilename);
! TreeCCStreamPrint(stream, "\t");
if(!(virt->oper->params->name) ||
!strcmp(virt->oper->params->name, "self"))
--- 225,229 ----
TreeCCStreamLine(stream, operCase->codeLinenum,
operCase->codeFilename);
! TreeCCStreamPrint(stream, " ");
if(!(virt->oper->params->name) ||
!strcmp(virt->oper->params->name, "self"))
***************
*** 236,245 ****
/* The first parameter is called
something else,
so create a temporary variable to
hold "this" */
! TreeCCStreamPrint(stream, "\n\t\t%s %s
= self\n\t",
actualNode->name,
virt->oper->params->name);
TreeCCStreamCodeIndent(stream,
operCase->code, 1);
}
! TreeCCStreamPrint(stream, "end\n");
TreeCCStreamFixLine(stream);
TreeCCStreamPrint(stream, "\n");
--- 237,246 ----
/* The first parameter is called
something else,
so create a temporary variable to
hold "this" */
! TreeCCStreamPrint(stream, "\n %s %s
= self\n ",
actualNode->name,
virt->oper->params->name);
TreeCCStreamCodeIndent(stream,
operCase->code, 1);
}
! TreeCCStreamPrint(stream, " end\n");
TreeCCStreamFixLine(stream);
TreeCCStreamPrint(stream, "\n");
***************
*** 247,251 ****
else
{
! TreeCCStreamPrint(stream, ")\n\n");
}
}
--- 248,252 ----
else
{
! TreeCCStreamPrint(stream, ")\n end\n");
}
}
***************
*** 321,327 ****
/* Ruby has handy accessor creating stuff */
/*TreeCCStreamPrint(stream,
! "\tpublic int getKind() { return kind__;
}\n");*/
TreeCCStreamPrint(stream,
! "\tattr_reader :kind\n");
if(context->track_lines)
--- 322,328 ----
/* Ruby has handy accessor creating stuff */
/*TreeCCStreamPrint(stream,
! " public int getKind() { return kind__;
}\n");*/
TreeCCStreamPrint(stream,
! " protected\n attr_reader :kind\n
public\n\n");
if(context->track_lines)
***************
*** 329,352 ****
/* A same kind of hack here*/
/*TreeCCStreamPrint(stream,
! "\tpublic String getFilename() { return
filename__; }\n");
TreeCCStreamPrint(stream,
! "\tpublic long getLinenum() { return linenum__;
}\n");
TreeCCStreamPrint(stream,
! "\tpublic void setFilename(String filename) "
"{ filename__ = filename; }\n");
TreeCCStreamPrint(stream,
! "\tpublic void setLinenum(long linenum) "
"{ linenum__ = linenum; }\n");*/
TreeCCStreamPrint(stream,
! "\tattr_accessor :linenum, :filename\n");
}
TreeCCStreamPrint(stream, "\n");
}
/* Declare the kind value */
/* Stick to the Ruby convention of constants, start with Uppercase,
continue with lowercase */
/* The parent doesn't matter, so don't check it */
! TreeCCStreamPrint(stream, "\tKind = %d;\n\n",
node->number);
--- 330,363 ----
/* A same kind of hack here*/
/*TreeCCStreamPrint(stream,
! " public String getFilename() { return
filename__; }\n");
TreeCCStreamPrint(stream,
! " public long getLinenum() { return linenum__;
}\n");
TreeCCStreamPrint(stream,
! " public void setFilename(String filename) "
"{ filename__ = filename; }\n");
TreeCCStreamPrint(stream,
! " public void setLinenum(long linenum) "
"{ linenum__ = linenum; }\n");*/
TreeCCStreamPrint(stream,
! " attr_accessor :Linenum, :Filename\n");
}
TreeCCStreamPrint(stream, "\n");
}
+ /* Add the attr_accessor stuff for nodes specific to this node type */
+ field = node->fields;
+ while(field != 0)
+ {
+ TreeCCStreamPrint(stream, " attr_accessor :%s\n", field->name);
+ field = field->next;
+ }
+ /* End this section with an extra newline */
+ TreeCCStreamPrint(stream, "\n");
+
/* Declare the kind value */
/* Stick to the Ruby convention of constants, start with Uppercase,
continue with lowercase */
/* The parent doesn't matter, so don't check it */
! TreeCCStreamPrint(stream, " KIND = %d\n\n",
node->number);
***************
*** 356,360 ****
/* The constructor is ALWAYS called initialize */
! TreeCCStreamPrint(stream, "\tdef initialize(");
if(context->reentrant)
{
--- 367,371 ----
/* The constructor is ALWAYS called initialize */
! TreeCCStreamPrint(stream, " def initialize(");
if(context->reentrant)
{
***************
*** 377,382 ****
{
/* Do not use base, Ruby uses super for that */
! /*TreeCCStreamPrint(stream, "\t\t: base(");*/
! TreeCCStreamPrint(stream, "\t\tsuper(");
if(context->reentrant)
{
--- 388,393 ----
{
/* Do not use base, Ruby uses super for that */
! /*TreeCCStreamPrint(stream, " : base(");*/
! TreeCCStreamPrint(stream, " super(");
if(context->reentrant)
{
***************
*** 394,398 ****
/* Set the node kind */
! TreeCCStreamPrint(stream, "address@hidden = Kind;\n");
/* Track the filename and line number if necessary */
--- 405,409 ----
/* Set the node kind */
! TreeCCStreamPrint(stream, " @kind = KIND\n");
/* Track the filename and line number if necessary */
***************
*** 402,416 ****
{
TreeCCStreamPrint(stream,
! "address@hidden =
@state.currFilename\n");
TreeCCStreamPrint(stream,
! "address@hidden =
@state.currLinenum\n");
}
else
{
TreeCCStreamPrint(stream,
! "address@hidden =
%s.state.currFilename();\n",
context->state_type);
TreeCCStreamPrint(stream,
! "address@hidden =
%s.state.currLinenum();\n",
context->state_type);
}
--- 413,427 ----
{
TreeCCStreamPrint(stream,
! " @Filename =
@state.currFilename\n");
TreeCCStreamPrint(stream,
! " @Finenum = @state.currLinenum\n");
}
else
{
TreeCCStreamPrint(stream,
! " @Filename =
%s.state.currFilename()\n",
context->state_type);
TreeCCStreamPrint(stream,
! " @Linenum =
%s.state.currLinenum()\n",
context->state_type);
}
***************
*** 423,437 ****
if((field->flags & TREECC_FIELD_NOCREATE) == 0)
{
! TreeCCStreamPrint(stream, "\t\tself.%s = %s;\n",
field->name,
field->name);
}
else if(field->value)
{
! TreeCCStreamPrint(stream, "\t\tself.%s = %s;\n",
field->name,
field->value);
}
field = field->next;
}
! TreeCCStreamPrint(stream, "\tend\n\n");
/* Implement the virtual functions */
--- 434,448 ----
if((field->flags & TREECC_FIELD_NOCREATE) == 0)
{
! TreeCCStreamPrint(stream, " self.%s = %s\n",
field->name,
field->name);
}
else if(field->value)
{
! TreeCCStreamPrint(stream, " self.%s = %s\n",
field->name,
field->value);
}
field = field->next;
}
! TreeCCStreamPrint(stream, " end\n\n");
/* Implement the virtual functions */
***************
*** 440,462 ****
/* Declare the "isA" and "getKindName" helper methods */
! TreeCCStreamPrint(stream, "\tdef isA(kind)\n");
! TreeCCStreamPrint(stream, "\t\tif(@kind == Kind) then\n");
! TreeCCStreamPrint(stream, "\t\t\treturn true;\n");
! TreeCCStreamPrint(stream, "\t\telse\n");
if(node->parent)
{
! TreeCCStreamPrint(stream, "\t\t\treturn super(kind);\n");
}
else
{
! TreeCCStreamPrint(stream, "\t\t\treturn 0;\n");
}
! TreeCCStreamPrint(stream, "\tend\n\n");
! TreeCCStreamPrint(stream, "\tdef kindname\n");
! TreeCCStreamPrint(stream, "\t\treturn \"%s\"\n", node->name);
! TreeCCStreamPrint(stream, "\tend\n");
/* Output the class footer */
--- 451,473 ----
/* Declare the "isA" and "getKindName" helper methods */
! TreeCCStreamPrint(stream, " def isA(kind)\n");
! TreeCCStreamPrint(stream, " if(@kind == KIND) then\n");
! TreeCCStreamPrint(stream, " return true\n");
! TreeCCStreamPrint(stream, " else\n");
if(node->parent)
{
! TreeCCStreamPrint(stream, " return super(kind)\n
end\n");
}
else
{
! TreeCCStreamPrint(stream, " return 0\n end\n");
}
! TreeCCStreamPrint(stream, " end\n\n");
! TreeCCStreamPrint(stream, " def KindName\n");
! TreeCCStreamPrint(stream, " return \"%s\"\n", node->name);
! TreeCCStreamPrint(stream, " end\n");
/* Output the class footer */
***************
*** 554,558 ****
/* Output the start of the function definition */
! TreeCCStreamPrint(stream, "\tdef %s %sCreate(",
node->name, node->name);
--- 565,569 ----
/* Output the start of the function definition */
! TreeCCStreamPrint(stream, " def %s %sCreate(",
node->name, node->name);
***************
*** 569,576 ****
{
TreeCCStreamPrint(stream, ")\n");
! TreeCCStreamPrint(stream, "\t\treturn %s.new(this", node->name);
FactoryInvokeParams(context, stream, node, 1);
TreeCCStreamPrint(stream, ")\n");
! TreeCCStreamPrint(stream, "\tend\n\n");
}
}
--- 580,587 ----
{
TreeCCStreamPrint(stream, ")\n");
! TreeCCStreamPrint(stream, " return %s.new(this", node->name);
FactoryInvokeParams(context, stream, node, 1);
TreeCCStreamPrint(stream, ")\n");
! TreeCCStreamPrint(stream, " end\n\n");
}
}
***************
*** 584,597 ****
context->state_type);
/* Singleton handling for non-reentrant systems */
if(!(context->reentrant))
{
! TreeCCStreamPrint(stream, "\tdef state\n");
! TreeCCStreamPrint(stream, "\t\tif(@state != null) return
@state\n");
! TreeCCStreamPrint(stream, "address@hidden = %s.new()\n",
context->state_type);
! TreeCCStreamPrint(stream, "\t\treturn @state;\n");
! TreeCCStreamPrint(stream, "\tend\n\n");
}
--- 595,609 ----
context->state_type);
+ TreeCCStreamPrint(stream, " @@state = nil\n");
/* Singleton handling for non-reentrant systems */
if(!(context->reentrant))
{
! TreeCCStreamPrint(stream, " def %s.state\n",
context->state_type);
! TreeCCStreamPrint(stream, " return @@state unless
@@state.nil?\n");
! TreeCCStreamPrint(stream, " @@state = %s.new()\n",
context->state_type);
! TreeCCStreamPrint(stream, " return @@state\n");
! TreeCCStreamPrint(stream, " end\n\n");
}
***************
*** 603,607 ****
else
{
! TreeCCStreamPrint(stream, "\tdef intialize \n address@hidden =
self \n \tend\n\n");
}
--- 615,619 ----
else
{
! TreeCCStreamPrint(stream, " def intialize \n @@state =
self \n end\n\n");
}
***************
*** 616,622 ****
{
TreeCCStreamPrint(stream,
! "\tdef currFilename \n \t\treturn null \n\tend\n");
TreeCCStreamPrint(stream,
! "\tdef currLinenum \n \t\treturn 0 \n\tend\n\n");
}
--- 628,634 ----
{
TreeCCStreamPrint(stream,
! " def currFilename \n return nil \n end\n\n");
TreeCCStreamPrint(stream,
! " def currLinenum \n return 0 \n end\n\n");
}
***************
*** 683,686 ****
--- 695,1193 ----
}
+ /*
+ * Determine if a type name corresponds to an enumerated type.
+ */
+ static int IsEnumType(TreeCCContext *context, const char *type)
+ {
+ TreeCCNode *node = TreeCCNodeFindByType(context, type);
+ if(node)
+ {
+ if((node->flags & TREECC_NODE_ENUM) != 0)
+ {
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ /*
+ * Output spaces's for a specific level of indenting.
+ */
+ static void Indent(TreeCCStream *stream, int indent)
+ {
+ while(indent >= 4)
+ {
+ TreeCCStreamPrint(stream, " ");
+ indent -= 4;
+ }
+ if(indent == 1)
+ {
+ TreeCCStreamPrint(stream, " ");
+ }
+ else if(indent == 2)
+ {
+ TreeCCStreamPrint(stream, " ");
+ }
+ else if(indent == 3)
+ {
+ TreeCCStreamPrint(stream, " ");
+ }
+ }
+
+ /*
+ * Non-virtual code generation functions start here
+ */
+
+ /*
+ * Generate the start declarations for a non-virtual operation.
+ */
+ static void Ruby_GenStart(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperation *oper)
+ {
+ if(oper->className)
+ {
+ TreeCCStreamPrint(stream, "class %s\n", oper->className);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, "class %s\n", oper->name);
+ }
+ }
+
+ /*
+ * Generate the entry point for a non-virtual operation.
+ */
+ static void RubyGenEntry(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperation *oper, int number)
+ {
+ TreeCCParam *param;
+ int num;
+ int needComma;
+ char *cname;
+
+ if(oper->className)
+ {
+ cname = oper->className;
+ }
+ else
+ {
+ cname = oper->name;
+ }
+
+ if(number != -1)
+ {
+ TreeCCStreamPrint(stream, " private \n def %s.%s_split_%d__(",
+ cname, oper->name, number);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, " public \n def %s.%s(",
+ cname, oper->name);
+ }
+
+ param = oper->params;
+ num = 1;
+ needComma = 0;
+ while(param != 0)
+ {
+ if(needComma)
+ {
+ TreeCCStreamPrint(stream, ", ");
+ }
+ if(param->name)
+ {
+ TreeCCStreamPrint(stream, "%s", param->name);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, "p%d__", num);
+ ++num;
+ }
+ if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if(!IsEnumType(context, param->type))
+ {
+ TreeCCStreamPrint(stream, "__");
+ }
+ }
+ needComma = 1;
+ param = param->next;
+ }
+ TreeCCStreamPrint(stream, ")\n");
+ }
+
+ /*
+ * Generate the entry point for a non-virtual operation.
+ */
+ static void Ruby_GenEntry(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperation *oper)
+ {
+ RubyGenEntry(context, stream, oper, -1);
+ }
+
+ /*
+ * Generate the entry point for a split-out function.
+ */
+ static void Ruby_GenSplitEntry(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperation *oper, int
number)
+ {
+ RubyGenEntry(context, stream, oper, number);
+ }
+
+ /*
+ * Generate the head of a "switch" statement.
+ */
+ static void Ruby_GenSwitchHead(TreeCCContext *context, TreeCCStream *stream,
+ char *paramName, int
level, int isEnum)
+ {
+ Indent(stream, level * 2 + 2);
+ if(isEnum)
+ {
+ TreeCCStreamPrint(stream, "case %s\n", paramName);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, "case %s__.type::KIND\n", paramName);
+ }
+ Indent(stream, level * 2 + 2);
+ TreeCCStreamPrint(stream, "\n");
+ }
+
+ /*
+ * Generate a selector for a "switch" case.
+ */
+ static void Ruby_GenSelector(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCNode *node, int
level)
+ {
+ if((node->flags & TREECC_NODE_ENUM_VALUE) != 0)
+ {
+ Indent(stream, level * 2 + 3);
+ TreeCCStreamPrint(stream, "when %s.%s\n",
+ node->parent->name,
node->name);
+ }
+ else if((node->flags & TREECC_NODE_ENUM) == 0)
+ {
+ Indent(stream, level * 2 + 3);
+ TreeCCStreamPrint(stream, "when %s::KIND\n", node->name);
+ }
+ }
+
+ /*
+ * Terminate the selectors and begin the body of a "switch" case.
+ */
+ static void Ruby_GenEndSelectors(TreeCCContext *context, TreeCCStream *stream,
+ int level)
+ {
+ /* No use for this in Ruby */
+ }
+
+ /*
+ * Generate the code for a case within a function.
+ */
+ static void Ruby_GenCaseFunc(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperationCase
*operCase, int number)
+ {
+ TreeCCParam *param;
+ TreeCCTrigger *trigger;
+ int num;
+ int needComma;
+ char *type;
+ char *cname;
+
+ if(operCase->oper->className)
+ {
+ cname = operCase->oper->className;
+ }
+ else
+ {
+ cname = operCase->oper->name;
+ }
+
+ /* Output the header for the function */
+ TreeCCStreamPrint(stream, " private \n def %s.%s_%d__(",
+ cname, operCase->oper->name, number);
+ param = operCase->oper->params;
+ trigger = operCase->triggers;
+ num = 1;
+ needComma = 0;
+ while(param != 0)
+ {
+ if(needComma)
+ {
+ TreeCCStreamPrint(stream, ", ");
+ }
+ if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if((trigger->node->flags & TREECC_NODE_ENUM) == 0 &&
+ (trigger->node->flags & TREECC_NODE_ENUM_VALUE) == 0)
+ {
+ type = trigger->node->name;
+ }
+ else
+ {
+ type = param->type;
+ }
+ trigger = trigger->next;
+ }
+ else
+ {
+ type = param->type;
+ }
+ if(param->name)
+ {
+ TreeCCStreamPrint(stream, "%s", param->name);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, "p%d__", num);
+ ++num;
+ }
+ needComma = 1;
+ param = param->next;
+ }
+ TreeCCStreamPrint(stream, ")\n");
+
+ /* Output the code for the operation case */
+ if(operCase->code)
+ {
+ TreeCCStreamCodeIndent(stream, operCase->code, 1);
+ }
+ TreeCCStreamPrint(stream, "end\n");
+ TreeCCStreamPrint(stream, "\n");
+ }
+
+ /*
+ * Generate a call to a case function from within the "switch".
+ */
+ static void Ruby_GenCaseCall(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperationCase
*operCase, int number,
+ int level)
+ {
+ TreeCCParam *param;
+ TreeCCTrigger *trigger;
+ int num;
+ int needComma;
+
+ /* Indent to the correct level */
+ Indent(stream, level * 2 + 1);
+
+ /* Print out the call */
+ TreeCCStreamPrint(stream, "%s_%d__(", operCase->oper->name, number);
+ param = operCase->oper->params;
+ trigger = operCase->triggers;
+ num = 1;
+ needComma = 0;
+ while(param != 0)
+ {
+ if(needComma)
+ {
+ TreeCCStreamPrint(stream, ", ");
+ }
+ /* if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if((trigger->node->flags & TREECC_NODE_ENUM) == 0 &&
+ (trigger->node->flags & TREECC_NODE_ENUM_VALUE) == 0)
+ {
+ TreeCCStreamPrint(stream, "(%s)",
trigger->node->name);
+ }
+ }*/
+ if(param->name)
+ {
+ TreeCCStreamPrint(stream, "%s", param->name);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, "p%d__", num);
+ ++num;
+ }
+ if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if((trigger->node->flags & TREECC_NODE_ENUM) == 0 &&
+ (trigger->node->flags & TREECC_NODE_ENUM_VALUE) == 0)
+ {
+ TreeCCStreamPrint(stream, "__");
+ }
+ trigger = trigger->next;
+ }
+ needComma = 1;
+ param = param->next;
+ }
+ TreeCCStreamPrint(stream, ")\n");
+ }
+
+ /*
+ * Generate the code for a case inline within the "switch".
+ */
+ static void Ruby_GenCaseInline(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperationCase
*operCase, int level)
+ {
+ TreeCCParam *param;
+ TreeCCTrigger *trigger;
+
+ /* Copy the parameters to new variables of the correct types */
+ param = operCase->oper->params;
+ trigger = operCase->triggers;
+ while(param != 0)
+ {
+ if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if(param->name != 0)
+ {
+ if((trigger->node->flags & TREECC_NODE_ENUM) ==
0 &&
+ (trigger->node->flags &
TREECC_NODE_ENUM_VALUE) == 0)
+ {
+ Indent(stream, level * 2 + 4);
+ TreeCCStreamPrint(stream, "%s =
%s__;\n",
+
param->name, param->name);
+ }
+ }
+ trigger = trigger->next;
+ }
+ param = param->next;
+ }
+
+ /* Output the inline code for the case */
+ Indent(stream, level * 2 + 4);
+ if(operCase->code)
+ {
+ /* Multiply the indent level by two because every ident is one
space */
+ TreeCCStreamCodeIndentCustom
+ (stream, operCase->code,' ',(level * 2 + 3) * 2);
+ }
+ Indent(stream, level * 2 + 4);
+ TreeCCStreamPrint(stream, "\n");
+ }
+
+ /*
+ * Generate a call to a split function from within the "switch".
+ */
+ static void Ruby_GenCaseSplit(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperationCase
*operCase,
+ int number, int level)
+ {
+ TreeCCParam *param;
+ TreeCCTrigger *trigger;
+ int num;
+ int needComma;
+
+ /* Indent to the correct level */
+ Indent(stream, level * 2 + 2);
+
+ /* Print out the call */
+ TreeCCStreamPrint(stream, "%s_split_%d__(", operCase->oper->name,
number);
+ param = operCase->oper->params;
+ trigger = operCase->triggers;
+ num = 1;
+ needComma = 0;
+ while(param != 0)
+ {
+ if(needComma)
+ {
+ TreeCCStreamPrint(stream, ", ");
+ }
+ if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if((trigger->node->flags & TREECC_NODE_ENUM) == 0 &&
+ (trigger->node->flags & TREECC_NODE_ENUM_VALUE) == 0)
+ {
+ TreeCCStreamPrint(stream, "%s",
trigger->node->name);
+ }
+ }
+ if(param->name)
+ {
+ TreeCCStreamPrint(stream, "%s", param->name);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, "p%d__", num);
+ ++num;
+ }
+ if((param->flags & TREECC_PARAM_TRIGGER) != 0)
+ {
+ if((trigger->node->flags & TREECC_NODE_ENUM) == 0 &&
+ (trigger->node->flags & TREECC_NODE_ENUM_VALUE) == 0)
+ {
+ TreeCCStreamPrint(stream, "__");
+ }
+ trigger = trigger->next;
+ }
+ needComma = 1;
+ param = param->next;
+ }
+ TreeCCStreamPrint(stream, ")\n");
+ }
+
+ /*
+ * Terminate a "switch" case.
+ */
+ static void Ruby_GenEndCase(TreeCCContext *context, TreeCCStream *stream,
+ int level)
+ {
+ /*Indent(stream, level * 2 + 3);
+ TreeCCStreamPrint(stream, "\n");*/
+ }
+
+ /*
+ * Terminate the "switch" statement.
+ */
+ static void Ruby_GenEndSwitch(TreeCCContext *context, TreeCCStream *stream,
+ int level)
+ {
+ Indent(stream, level * 2 + 3);
+ TreeCCStreamPrint(stream, "else\n");
+ Indent(stream, level * 2 + 2);
+ TreeCCStreamPrint(stream, "end\n");
+ }
+
+ /*
+ * Generate the exit point for a non-virtual operation.
+ */
+ static void Ruby_GenExit(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperation *oper)
+ {
+ if(strcmp(oper->returnType, "void") != 0)
+ {
+ /* Generate a default return value for the function */
+ if(oper->defValue)
+ {
+ TreeCCStreamPrint(stream, " return %s\n",
oper->defValue);
+ }
+ else
+ {
+ TreeCCStreamPrint(stream, " return 0\n");
+ }
+ }
+ TreeCCStreamPrint(stream, " end\n");
+ }
+
+ /*
+ * Generate the end declarations for a non-virtual operation.
+ */
+ static void Ruby_GenEnd(TreeCCContext *context, TreeCCStream *stream,
+ TreeCCOperation *oper)
+ {
+ TreeCCStreamPrint(stream, "end\n");
+ }
+
+ /*
+ * Table of non-virtual code generation functions.
+ */
+ TreeCCNonVirtual const TreeCCNonVirtualFuncsRuby = {
+ Ruby_GenStart,
+ Ruby_GenEntry,
+ Ruby_GenSplitEntry,
+ Ruby_GenSwitchHead,
+ Ruby_GenSelector,
+ Ruby_GenEndSelectors,
+ Ruby_GenCaseFunc,
+ Ruby_GenCaseCall,
+ Ruby_GenCaseInline,
+ Ruby_GenCaseSplit,
+ Ruby_GenEndCase,
+ Ruby_GenEndSwitch,
+ Ruby_GenExit,
+ Ruby_GenEnd,
+ };
+
void TreeCCGenerateRuby(TreeCCContext *context)
{
***************
*** 699,703 ****
}
TreeCCNodeVisitAll(context, BuildTypeDecls);
! TreeCCGenerateNonVirtuals(context, &TreeCCNonVirtualFuncsJava);
/* Write all stream footers */
--- 1206,1212 ----
}
TreeCCNodeVisitAll(context, BuildTypeDecls);
! /* NO JAVA PLEASE */
! TreeCCGenerateNonVirtuals(context, &TreeCCNonVirtualFuncsRuby);
!
/* Write all stream footers */
Index: stream.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/treecc/stream.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** stream.h 17 Mar 2002 10:35:28 -0000 1.2
--- stream.h 9 Nov 2002 11:36:26 -0000 1.3
***************
*** 148,151 ****
--- 148,158 ----
/*
+ * Output a block of literal code to a stream which is indented.
+ * The first line is not indented. This version supports custom indent chars.
+ */
+ void TreeCCStreamCodeIndentCustom(TreeCCStream *stream, char *code,
+ char
indentchar, int indent);
+
+ /*
* Fix the line number information in the output stream
* after outputting a block of code.
Index: stream.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/treecc/stream.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** stream.c 17 Mar 2002 10:35:28 -0000 1.2
--- stream.c 9 Nov 2002 11:36:26 -0000 1.3
***************
*** 505,508 ****
--- 505,528 ----
}
+ void TreeCCStreamCodeIndentCustom(TreeCCStream *stream, char *code,
+ char
indentchar, int indent)
+ {
+ int temp;
+ while(*code != '\0')
+ {
+ StreamPut(*code, stream);
+ if(*code == '\n')
+ {
+ ++(stream->linenum);
+ for(temp = 0; temp < indent; ++temp)
+ {
+ StreamPut(indentchar, stream);
+ }
+ }
+ ++code;
+ }
+ }
+
+
void TreeCCStreamFixLine(TreeCCStream *stream)
{
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/treecc/ChangeLog,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -r1.49 -r1.50
*** ChangeLog 5 Nov 2002 03:48:53 -0000 1.49
--- ChangeLog 9 Nov 2002 11:36:26 -0000 1.50
***************
*** 1,3 ****
--- 1,12 ----
+ 2002-11-09 Peter Minten <address@hidden>
+ * gen_ruby.c: Modified to create code compliant with Ruby markup
+ conventions, also some little bug fixes.
+
+ * examples/expr_ruby.tc: Improved example.
+
+ * stream.h, stream.c: Overloaded TreeCCStreamCodeIndent
+ to support languages that don't use tabs for indenting.
+
2002-11-05 Rhys Weatherley <address@hidden>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: treecc gen_ruby.c,1.1,1.2 stream.h,1.2,1.3 stream.c,1.2,1.3 ChangeLog,1.49,1.50,
Peter Minten <address@hidden> <=