Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Added RDoc to the native code.
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d0fceeeb51842abb9b60cbb370b7dafbde4b79da
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 9 10:25:02 2008 -0700

    rdocing native_initialize

commit 0a0efb23a53e487bb91fa95aef62b857b8d254b8
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 9 10:22:50 2008 -0700

    Rdoc'd RubyLandProxy.

commit 63207580fae6a97ef8b7cbea36b13be65b87e987
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 9 09:02:05 2008 -0700

    documenting immutable node

commit 6383e54f1f9dd526b36b9b216e5f80805f290869
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri May 9 08:40:42 2008 -0700

    adding some rdoc
  • Loading branch information
tenderlove committed May 9, 2008
1 parent 17c4395 commit 2fc2742
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 62 deletions.
8 changes: 7 additions & 1 deletion ext/spidermonkey/context.c
Expand Up @@ -121,7 +121,13 @@ static JSBool branch_callback(JSContext* js, JSScript* UNUSED(script))
return JS_TRUE;
}

/* private */ static VALUE /* Context#initialize_native(options={}) */
/*
* call-seq:
* native_initialize(options={})
*
* Initializes the native spidermonkey values.
*/
static VALUE
initialize_native(VALUE self, VALUE UNUSED(options))
{
OurContext* context;
Expand Down
5 changes: 5 additions & 0 deletions ext/spidermonkey/error.c
Expand Up @@ -4,6 +4,11 @@ static VALUE error = Qnil;

void init_Johnson_Error(VALUE johnson)
{
/* HACK: These comments are *only* to make RDoc happy.
VALUE johnson = rb_define_module("Johnson");
*/

/* Johnson::Error class. */
error = rb_define_class_under(johnson, "Error", rb_eStandardError);
}

Expand Down
192 changes: 152 additions & 40 deletions ext/spidermonkey/immutable_node.c.erb
Expand Up @@ -27,6 +27,12 @@ static VALUE allocate(VALUE klass)
return self;
}

/*
* call-seq:
* parse_io(stream, filename=nil, line_number=0)
*
* Parses an IO object, returning a native spidermonkey parse tree.
*/
static VALUE parse_io(int argc, VALUE *argv, VALUE klass) {
VALUE self = allocate(klass);
VALUE stream, filename, linenum;
Expand Down Expand Up @@ -81,24 +87,39 @@ static VALUE parse_io(int argc, VALUE *argv, VALUE klass) {
return self;
}

static VALUE /* line */
line(VALUE self) {
/*
* call-seq:
* line
*
* Returns the line number of the node.
*/
static VALUE line(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
return INT2NUM(ctx->node->pn_pos.begin.lineno);
}

static VALUE /* index */
begin_index(VALUE self) {
/*
* call-seq:
* index
*
* Returns the column number of the node.
*/
static VALUE begin_index(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
return INT2NUM(ctx->node->pn_pos.begin.index);
}

static VALUE /* pn_arity */
pn_arity(VALUE self) {
/*
* call-seq:
* pn_arity
*
* Returns the arity of the node as a symbol.
*/
static VALUE pn_arity(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -121,8 +142,13 @@ pn_arity(VALUE self) {
return Qnil;
}

static VALUE /* pn_type */
pn_type(VALUE self) {
/*
* call-seq:
* pn_type
*
* Returns the type of the node as a symbol.
*/
static VALUE pn_type(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -134,8 +160,13 @@ pn_type(VALUE self) {
return INT2NUM(ctx->node->pn_type);
}

static VALUE /* pn_expr */
data_pn_expr(VALUE self) {
/*
* call-seq:
* pn_expr
*
* Returns the parse node expression as an ImmutableNode.
*/
static VALUE data_pn_expr(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -149,8 +180,13 @@ data_pn_expr(VALUE self) {
return Qnil;
}

static VALUE /* pn_kid */
data_pn_kid(VALUE self) {
/*
* call-seq:
* pn_kid
*
* Returns the child ImmutableNode.
*/
static VALUE data_pn_kid(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -164,8 +200,13 @@ data_pn_kid(VALUE self) {
return Qnil;
}

static VALUE /* pn_kid1 */
data_pn_kid1(VALUE self) {
/*
* call-seq:
* pn_kid1
*
* Returns the first child ImmutableNode.
*/
static VALUE data_pn_kid1(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -179,8 +220,13 @@ data_pn_kid1(VALUE self) {
return Qnil;
}

static VALUE /* pn_kid2 */
data_pn_kid2(VALUE self) {
/*
* call-seq:
* pn_kid2
*
* Returns the second child ImmutableNode.
*/
static VALUE data_pn_kid2(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -194,8 +240,13 @@ data_pn_kid2(VALUE self) {
return Qnil;
}

static VALUE /* pn_kid3 */
data_pn_kid3(VALUE self) {
/*
* call-seq:
* pn_kid3
*
* Returns the third child ImmutableNode.
*/
static VALUE data_pn_kid3(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -209,8 +260,13 @@ data_pn_kid3(VALUE self) {
return Qnil;
}

static VALUE /* pn_dval */
data_pn_dval(VALUE self) {
/*
* call-seq:
* pn_dval
*
* Returns the numeric value of the node.
*/
static VALUE data_pn_dval(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -221,8 +277,13 @@ data_pn_dval(VALUE self) {
}
}

static VALUE /* pn_op */
data_pn_op(VALUE self) {
/*
* call-seq:
* pn_op
*
* Returns the op code for the node as a symbol.
*/
static VALUE data_pn_op(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -234,8 +295,13 @@ data_pn_op(VALUE self) {
return INT2NUM(ctx->node->pn_op);
}

static VALUE /* pn_left */
data_pn_left(VALUE self) {
/*
* call-seq:
* pn_left
*
* Returns the left side ImmutableNode.
*/
static VALUE data_pn_left(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
Expand All @@ -250,25 +316,40 @@ data_pn_left(VALUE self) {
return Qnil;
}

static VALUE /* pn_extra */
data_pn_extra(VALUE self) {
/*
* call-seq:
* pn_extra
*
* Returns extra informaton about the node as an Integer.
*/
static VALUE data_pn_extra(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);

return INT2NUM(ctx->node->pn_extra);
}

static VALUE /* name */
name(VALUE self) {
/*
* call-seq:
* name
*
* Returns the name of the node.
*/
static VALUE name(VALUE self) {
ImmutableNodeContext * ctx;

Data_Get_Struct(self, ImmutableNodeContext, ctx);
return rb_str_new2(JS_GetStringBytes(ATOM_TO_STRING(ctx->node->pn_atom)));
}

static VALUE /* regexp */
regexp(VALUE self) {
/*
* call-seq:
* regexp
*
* Returns the regexp value as a String.
*/
static VALUE regexp(VALUE self) {
ImmutableNodeContext * ctx;
jsval result;

Expand All @@ -277,8 +358,13 @@ regexp(VALUE self) {
return rb_str_new2(JS_GetStringBytes(JSVAL_TO_STRING(result)));
}

static VALUE /* function_name */
function_name(VALUE self) {
/*
* call-seq:
* function_name
*
* Returns the function name as a String.
*/
static VALUE function_name(VALUE self) {
ImmutableNodeContext * ctx;
JSFunction * f;
JSObject * object;
Expand All @@ -294,8 +380,13 @@ function_name(VALUE self) {
}
}

static VALUE /* function_args */
function_args(VALUE self) {
/*
* call-seq:
* function_args
*
* Returns the function argument names as an Array of String.
*/
static VALUE function_args(VALUE self) {
ImmutableNodeContext * ctx;
JSFunction * f;
JSObject * object;
Expand All @@ -319,8 +410,13 @@ function_args(VALUE self) {
return func_args;
}

static VALUE /* function_body */
function_body(VALUE self) {
/*
* call-seq:
* function_body
*
* Returns the function body as an ImmutableNode.
*/
static VALUE function_body(VALUE self) {
ImmutableNodeContext * ctx;
JSFunction * f;
JSObject * object;
Expand All @@ -339,8 +435,13 @@ function_body(VALUE self) {
return Qnil;
}

static VALUE /* pn_right */
data_pn_right(VALUE self)
/*
* call-seq:
* pn_right
*
* Returns right side as an ImmutableNode.
*/
static VALUE data_pn_right(VALUE self)
{
ImmutableNodeContext * ctx;

Expand All @@ -356,8 +457,13 @@ data_pn_right(VALUE self)
return Qnil;
}

static VALUE /* children */
children(VALUE self) {
/*
* call-seq:
* children
*
* Returns children as an Array of ImmutableNode.
*/
static VALUE children(VALUE self) {
ImmutableNodeContext * ctx;
JSParseNode * p;
VALUE children;
Expand All @@ -378,6 +484,12 @@ children(VALUE self) {

void init_Johnson_SpiderMonkey_Immutable_Node(VALUE spidermonkey)
{
/* HACK: These comments are *only* to make RDoc happy.
VALUE johnson = rb_define_module("Johnson");
VALUE spidermonkey = rb_define_module_under(johnson, "SpiderMonkey");
*/

/* ImmutableNode class. */
cNode = rb_define_class_under(spidermonkey, "ImmutableNode", rb_cObject);

rb_define_alloc_func(cNode, allocate);
Expand Down

0 comments on commit 2fc2742

Please sign in to comment.