[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/JScript/Nodes .cvsignore,NONE,1.1 AS
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/JScript/Nodes .cvsignore,NONE,1.1 AST.cs,NONE,1.1 Block.cs,NONE,1.1 CodeBase.cs,NONE,1.1 Context.cs,NONE,1.1 JExpr.tc,NONE,1.1 JNode.tc,NONE,1.1 JStmt.tc,NONE,1.1 Makefile,NONE,1.1 ScriptBlock.cs,NONE,1.1 |
Date: |
Mon, 13 Jan 2003 05:53:23 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/JScript/Nodes
In directory subversions:/tmp/cvs-serv3129/JScript/Nodes
Added Files:
.cvsignore AST.cs Block.cs CodeBase.cs Context.cs JExpr.tc
JNode.tc JStmt.tc Makefile ScriptBlock.cs
Log Message:
Perform the initial check-in of the JScript implementation (requires
treecc 0.2.0 or higher).
--- NEW FILE ---
JNode.cs
--- NEW FILE ---
/*
* AST.cs - Root of the abstract syntax tree structure.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
// The "AST" class is the root of the abstract syntax tree, as seen by
// API callers. The "real" abstract syntax tree is managed by "treecc",
// rooted at the "JNode" class. See "JNode.tc" for details.
//
// The "AST" class and its descendents should probably be "internal", but
// we have to declare them "public" for backwards-compatibility. Because
// the constructors are "internal", there is no way for callers to inherit.
public abstract class AST
{
// Private state - wrap up a JNode.
internal JNode jnode;
// Constructors.
internal AST() {}
internal AST(JNode jnode)
{
this.jnode = jnode;
}
}; // class AST
}; // namespace Microsoft.JScript
--- NEW FILE ---
/*
* Block.cs - Lexical block.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
// Dummy class for backwards-compatibility.
public sealed class Block : AST
{
// Constructor.
internal Block(JNode jnode) : base(jnode) {}
}; // class Block
}; // namespace Microsoft.JScript
--- NEW FILE ---
/*
* CodeBase.cs - Information about a code base that is attached to a context.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
using Microsoft.Vsa;
internal sealed class CodeBase
{
// Accessible internal state.
public String name;
public IVsaItem item;
public IVsaSite site;
// Constructor.
public CodeBase(String name, IVsaItem item)
{
this.name = name;
this.item = item;
this.site = null;
}
public CodeBase(String name, IVsaItem item, IVsaSite site)
{
this.name = name;
this.item = item;
this.site = site;
}
}; // class CodeBase
}; // namespace Microsoft.JScript
--- NEW FILE ---
/*
* Context.cs - Context information for an AST node.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
public class Context
{
// Private state.
internal CodeBase codebase;
internal int startPosition;
internal int endPosition;
internal int startLine;
internal int startLinePosition;
internal int endLine;
internal int endLinePosition;
internal JSToken token;
internal String source;
// Constructors.
internal Context(String source)
{
startPosition = 0;
endPosition = source.Length;
startLine = 1;
startLinePosition = 0;
endLine = 1;
endLinePosition = 0;
token = JSToken.None;
this.source = source;
}
// Get the first column occupied by the construct.
public int StartColumn
{
get
{
return startPosition -
startLinePosition;
}
}
// Get the first line occupied by the construct.
public int StartLine
{
get
{
return startLine;
}
}
// Get the construct's first position within the source string.
public int StartPosition
{
get
{
return startPosition;
}
}
// Get the last column occupied by the construct.
public int EndColumn
{
get
{
return endPosition - endLinePosition;
}
}
// Get the last line occupied by the construct.
public int EndLine
{
get
{
return endLine;
}
}
// Get the construct's last position within the source string.
public int EndPosition
{
get
{
return endPosition;
}
}
// Get the source code for the construct.
public String GetCode()
{
if(startPosition < endPosition && endPosition
<= source.Length)
{
return source.Substring
(startPosition, endPosition -
startPosition);
}
else
{
return null;
}
}
// Get the token code for the construct.
public JSToken GetToken()
{
return token;
}
// Make a copy of this context.
internal Context MakeCopy()
{
return (Context)(MemberwiseClone());
}
// Build a new context object that covers a range of nodes.
internal static Context BuildRange(Context start, Context end)
{
Context context = new Context(start.source);
context.codebase = start.codebase;
context.token = start.token;
context.startPosition = start.startPosition;
context.startLine = start.startLine;
context.startLinePosition =
start.startLinePosition;
context.endLine = end.endLine;
context.endLinePosition = end.endLinePosition;
return context;
}
}; // class Context
}; // namespace Microsoft.JScript
--- NEW FILE ---
/*
* JExpr.tc - Input file for "treecc" that defines JScript expression nodes.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Evaluate constants.
Eval(JConstant)
{
return value;
}
// Evaluate "undefined" constants.
Eval(JUndefined)
{
return null;
}
// Evaluate expression list elements.
Eval(JExprListElem)
{
// Nothing to do here: handled by the higher level.
return null;
}
// Evaluate array literals.
Eval(JArrayLiteral)
{
// Create a new instance of "Array".
ArrayObject value = new ArrayObject
(EngineInstance.GetEngineInstance(engine).GetArrayPrototype());
// Evaluate and add the elements.
JExprListElem elem = first;
int index = 0;
while(elem != null)
{
value[index] = elem.expr.Eval(engine);
elem = elem.next;
}
// Return the object to the caller.
return value;
}
// Evaluate object literals.
Eval(JObjectLiteral)
{
// Create a new instance of "Object".
JSObject value = new JSObject(EngineInstance.GetEngineInstance(engine)
.GetObjectPrototype());
// Evaluate and add the properties.
JExprListElem elem = first;
while(elem != null)
{
value.SetProperty(Convert.ToString(elem.name),
elem.expr.Eval(engine),
PropertyAttributes.None);
elem = elem.next;
}
// Return the object to the caller.
return value;
}
// Evaluate the "this" value.
Eval(JThis),
Eval(JSuper)
{
// TODO
return null;
}
// Evaluate identifiers in the current execution context.
Eval(JIdentifier)
{
// TODO
return null;
}
// Evaluate "as is" nodes, which are typically used to surround
// bracketed expressions to allow "identifier" and "(identifier)"
// to be distinguished in statement label positions.
Eval(JAsIs)
{
return expr.Eval(engine);
}
// Evaluate "comma" nodes.
Eval(JComma)
{
expr1.Eval(engine);
return expr2.Eval(engine);
}
// Evaluate an assignment statement.
Eval(JAssign)
{
Object data1 = null;
Object data2 = null;
Object value;
expr1.Prepare(engine, ref data1, ref data2);
value = expr2.Eval(engine);
expr1.Store(engine, data1, data2, value);
return value;
}
// Evaluate an operator-based assignment statement.
Eval(JAssignOp)
{
Object data1 = null;
Object data2 = null;
Object value1, value2;
value1 = expr1.GetAndPrepare(engine, ref data1, ref data2);
value2 = expr2.Eval(engine);
// TODO: compute "value1 op value2".
expr1.Store(engine, data1, data2, value1);
return value1;
}
// Evaluate a conditional expression.
Eval(JIfExpr)
{
Object value = expr1.Eval(engine);
if(Convert.ToBoolean(value))
{
return expr2.Eval(engine);
}
else
{
return expr3.Eval(engine);
}
}
// Evaluate a logical OR expression.
Eval(JLogicalOr)
{
Object value = expr1.Eval(engine);
if(Convert.ToBoolean(value))
{
return value;
}
else
{
return expr2.Eval(engine);
}
}
// Evaluate a logical AND expression.
Eval(JLogicalAnd)
{
Object value = expr1.Eval(engine);
if(!Convert.ToBoolean(value))
{
return value;
}
else
{
return expr2.Eval(engine);
}
}
// Evaluate a bitwise OR expression.
Eval(JBitwiseOr)
{
// TODO
return null;
}
// Evaluate a bitwise XOR expression.
Eval(JBitwiseXor)
{
// TODO
return null;
}
// Evaluate a bitwise AND expression.
Eval(JBitwiseAnd)
{
// TODO
return null;
}
// Evaluate an equality expression.
Eval(JEq)
{
// TODO
return null;
}
// Evaluate an inequality expression.
Eval(JNe)
{
// TODO
return null;
}
// Evaluate a strict equality expression.
Eval(JStrictEq)
{
// TODO
return null;
}
// Evaluate a strict inequality expression.
Eval(JStrictNe)
{
// TODO
return null;
}
// Evaluate a less than expression.
Eval(JLt)
{
// TODO
return null;
}
// Evaluate a less than or equal expression.
Eval(JLe)
{
// TODO
return null;
}
// Evaluate a greater than expression.
Eval(JGt)
{
// TODO
return null;
}
// Evaluate a greater than or equal expression.
Eval(JGe)
{
// TODO
return null;
}
// Evaluate an "instanceof" expression.
Eval(JInstanceof)
{
// TODO
return null;
}
// Evaluate an "in" expression.
Eval(JIn)
{
// TODO
return null;
}
// Evaluate a left shift expression.
Eval(JShl)
{
// TODO
return null;
}
// Evaluate a right shift expression.
Eval(JShr)
{
// TODO
return null;
}
// Evaluate an unsigned right shift expression.
Eval(JUShr)
{
// TODO
return null;
}
// Evaluate an addition expression.
Eval(JAdd)
{
// TODO
return null;
}
// Evaluate a subtraction expression.
Eval(JSub)
{
// TODO
return null;
}
// Evaluate a multiplication expression.
Eval(JMul)
{
// TODO
return null;
}
// Evaluate a division expression.
Eval(JDiv)
{
// TODO
return null;
}
// Evaluate a remainder expression.
Eval(JRem)
{
// TODO
return null;
}
// Evaluate a negate expression.
Eval(JNeg)
{
// TODO
return null;
}
// Evaluate a unary plus expression.
Eval(JUnaryPlus)
{
// TODO
return null;
}
// Evaluate a "delete" expression.
Eval(JDelete)
{
// TODO
return null;
}
// Evaluate a "void" expression.
Eval(JVoid)
{
// Evaluate the sub-expression and then return "undefined".
expr.Eval(engine);
return null;
}
// Evaluate a "typeof" expression.
Eval(JTypeof)
{
return Support.Typeof(expr.Eval(engine));
}
// Evaluate a pre-increment expression.
Eval(JPreInc)
{
// TODO
return null;
}
// Evaluate a pre-decrement expression.
Eval(JPreDec)
{
// TODO
return null;
}
// Evaluate a post-increment expression.
Eval(JPostInc)
{
// TODO
return null;
}
// Evaluate a post-decrement expression.
Eval(JPostDec)
{
// TODO
return null;
}
// Evaluate a bitwise NOT expression.
Eval(JBitwiseNot)
{
// TODO
return null;
}
// Evaluate a logical NOT expression.
Eval(JLogicalNot)
{
if(Convert.ToBoolean(expr.Eval(engine)))
{
return false;
}
else
{
return true;
}
}
// Evaluate a "new" expression.
Eval(JNew)
{
// TODO
return null;
}
// Evaluate an array access expression.
Eval(JArrayAccess)
{
// TODO
return null;
}
// Evaluate a field access expression.
Eval(JFieldAccess)
{
// TODO
return null;
}
// Evaluate a function call expression.
Eval(JCall)
{
// TODO
return null;
}
// Evaluate an argument list expression.
Eval(JArgList)
{
// TODO
return null;
}
// Evaluate an "eval" expression.
Eval(JEval)
{
return Microsoft.JScript.Eval.JScriptEvaluate(expr.Eval(engine),
engine);
}
// Evaluate a "print" expression.
Eval(JPrint)
{
Object value = expr.Eval(engine);
String pvalue;
if(value is ArrayObject)
{
pvalue = ArrayPrototype.join(value, String.Empty);
}
else
{
pvalue = Convert.ToString(value);
}
Console.WriteLine(pvalue);
return Empty.Value;
}
--- NEW FILE ---
%{
/*
* JNode.tc - Input file for "treecc" that defines the JScript nodes.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using Microsoft.JScript.Vsa;
using System.Reflection;
%}
// Configure treecc the way we want it.
%option lang = "C#"
%option internal_access
%option no_track_lines
%option state_type = "JNodeState"
%option namespace = "Microsoft.JScript"
// Define the nodes.
%node JNode %abstract %typedef =
{
Context context;
}
%node JScriptBlock JNode =
{
JNode functions;
JNode statements;
}
%node JBlock JNode =
{
JNode statements;
}
// Constant and literal nodes.
%node JConstant JNode =
{
Object value;
}
%node JUndefined JNode
%node JExprList JNode %abstract =
{
%nocreate JExprListElem first = {null};
%nocreate JExprListElem last = {null};
}
%node JExprListElem JNode =
{
Object name;
JNode expr;
JExprListElem next;
}
%node JArrayLiteral JExprList =
{
int size;
}
%node JObjectLiteral JExprList
// Expression nodes.
%node JThis JNode
%node JSuper JNode
%node JIdentifier JNode =
{
String name;
}
%node JUnaryExpression JNode %abstract =
{
JNode expr;
}
%node JBinaryExpression JNode %abstract =
{
JNode expr1;
JNode expr2;
}
%node JAsIs JUnaryExpression
%node JComma JBinaryExpression
%node JAssign JNode =
{
JNode expr1;
JNode expr2;
}
%node JAssignOp JNode =
{
JSToken oper;
JNode expr1;
JNode expr2;
}
%node JIfExpr JNode =
{
JNode expr1;
JNode expr2;
JNode expr3;
}
%node JLogicalOr JBinaryExpression
%node JLogicalAnd JBinaryExpression
%node JBitwiseOr JBinaryExpression
%node JBitwiseXor JBinaryExpression
%node JBitwiseAnd JBinaryExpression
%node JEq JBinaryExpression
%node JNe JBinaryExpression
%node JStrictEq JBinaryExpression
%node JStrictNe JBinaryExpression
%node JLt JBinaryExpression
%node JLe JBinaryExpression
%node JGt JBinaryExpression
%node JGe JBinaryExpression
%node JInstanceof JBinaryExpression
%node JIn JBinaryExpression
%node JShl JBinaryExpression
%node JShr JBinaryExpression
%node JUShr JBinaryExpression
%node JAdd JBinaryExpression
%node JSub JBinaryExpression
%node JMul JBinaryExpression
%node JDiv JBinaryExpression
%node JRem JBinaryExpression
%node JNeg JUnaryExpression
%node JUnaryPlus JUnaryExpression
%node JDelete JUnaryExpression
%node JVoid JUnaryExpression
%node JTypeof JUnaryExpression
%node JPreInc JUnaryExpression
%node JPreDec JUnaryExpression
%node JPostInc JUnaryExpression
%node JPostDec JUnaryExpression
%node JBitwiseNot JUnaryExpression
%node JLogicalNot JUnaryExpression
%node JNew JBinaryExpression
%node JArrayAccess JBinaryExpression
%node JFieldAccess JNode =
{
JNode expr;
String name;
}
%node JCall JBinaryExpression
%node JArgList JBinaryExpression
%node JEval JUnaryExpression
%node JPrint JUnaryExpression
// Statement nodes.
%node JStatement JNode %abstract =
{
%nocreate String[] labels;
}
%node JEmpty JStatement
%node JCompound JStatement =
{
%nocreate JNode stmt1;
%nocreate JNode stmt2;
%nocreate JNode stmt3;
%nocreate JNode stmt4;
%nocreate JCompound next;
}
%node JExprStmt JStatement =
{
JNode expr;
}
%node JIf JStatement =
{
JNode condition;
JNode thenClause;
JNode elseClause;
}
%node JWhile JStatement =
{
JNode condition;
JNode body;
}
%node JDo JStatement =
{
JNode body;
JNode condition;
}
%node JFor JStatement =
{
JNode init;
JNode cond;
JNode incr;
JNode body;
}
%node JForIn JStatement =
{
JNode decl;
JNode expr;
JNode body;
}
%node JSwitch JStatement =
{
JNode expr;
JNode cases;
}
%node JCase JStatement =
{
JNode expr;
JNode body;
}
%node JDefault JStatement =
{
JNode body;
}
%node JFallThrough JStatement =
{
JNode stmt;
}
%node JContinue JStatement =
{
String label;
}
%node JBreak JStatement =
{
String label;
}
%node JReturn JStatement
%node JReturnExpr JStatement =
{
JNode expr;
}
%node JThrow JStatement =
{
JNode expr;
}
%node JWith JStatement =
{
JNode expr;
JNode body;
}
%node JVarDecl JStatement =
{
String name;
JNode initializer;
}
%node JTry JStatement =
{
JNode body;
String catchName;
JNode catchClause;
JNode finallyClause;
}
// Function definitions.
%node JFunction JNode =
{
String name;
JFormalParams fparams;
JNode body;
}
%node JFormalParams JExprList
// Declare the evaluation operation on nodes.
%operation %virtual Object Eval([JNode this], VsaEngine engine)
// Declare the assignment preparation operation on nodes.
%operation %virtual void Prepare([JNode this], VsaEngine engine,
ref Object
data1, ref Object data2)
// Declare the assignment get-preparation operation on nodes.
%operation %virtual Object GetAndPrepare([JNode this], VsaEngine engine,
ref Object data1, ref Object data2)
// Declare the assignment store operation on nodes.
%operation %virtual void Store([JNode this], VsaEngine engine,
Object data1, Object
data2, Object value)
// Stub out assignment for most node types.
Prepare(JNode),
GetAndPrepare(JNode),
Store(JNode)
{
throw new JScriptException(JSError.IllegalAssignment, context);
}
// Evaluate script blocks.
Eval(JScriptBlock)
{
// TODO: declare the functions into the global scope.
// Execute the global statements within the block.
if(statements != null)
{
return statements.Eval(engine);
}
else
{
return Empty.Value;
}
}
// Evaluate regular "eval" blocks.
Eval(JBlock)
{
if(statements != null)
{
return statements.Eval(engine);
}
else
{
return Empty.Value;
}
}
// Evaluate a function definition.
Eval(JFunction)
{
// TODO
return null;
}
// Evaluate a formal parameter list.
Eval(JFormalParams)
{
// Never called - nothing to do here.
return null;
}
// Include operation cases for expressions and statements.
%include "JExpr.tc"
%include "JStmt.tc"
--- NEW FILE ---
/*
* JStmt.tc - Input file for "treecc" that defines JScript statment nodes.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Evaluate the empty statement.
Eval(JEmpty)
{
return Empty.Value;
}
// Evaluate a compound statement.
Eval(JCompound)
{
Object last = Empty.Value;
JCompound node = this;
do
{
if(node.stmt1 != null)
{
last = node.stmt1.Eval(engine);
}
if(node.stmt2 != null)
{
last = node.stmt2.Eval(engine);
}
if(node.stmt3 != null)
{
last = node.stmt3.Eval(engine);
}
if(node.stmt4 != null)
{
last = node.stmt4.Eval(engine);
}
node = node.next;
}
while(node != null);
return last;
}
// Evaluate an expression statement.
Eval(JExprStmt)
{
return expr.Eval(engine);
}
// Evaluate an "if" statement.
Eval(JIf)
{
Object value = condition.Eval(engine);
if(Convert.ToBoolean(value))
{
if(thenClause != null)
{
return thenClause.Eval(engine);
}
}
else
{
if(elseClause != null)
{
return elseClause.Eval(engine);
}
}
return Empty.Value;
}
// Evaluate a "while" statement.
Eval(JWhile)
{
Object result = Empty.Value;
Object temp;
try
{
while(Convert.ToBoolean(condition.Eval(engine)))
{
try
{
if(body != null)
{
temp = body.Eval(engine);
if(temp != Empty.Value)
{
result = temp;
}
}
}
catch(ContinueJumpOut cont)
{
// We received a "continue" from inside the
"while" loop.
if(!Support.LabelMatch(cont.label, labels))
{
throw;
}
}
}
}
catch(BreakJumpOut brk)
{
// We received a "break" from inside the "while" loop.
if(!Support.LabelMatch(brk.label, labels))
{
throw;
}
}
return result;
}
// Evaluate a "do" statement.
Eval(JDo)
{
Object result = Empty.Value;
Object temp;
try
{
do
{
try
{
if(body != null)
{
temp = body.Eval(engine);
if(temp != Empty.Value)
{
result = temp;
}
}
}
catch(ContinueJumpOut cont)
{
// We received a "continue" from inside the
"do" loop.
if(!Support.LabelMatch(cont.label, labels))
{
throw;
}
}
}
while(Convert.ToBoolean(condition.Eval(engine)));
}
catch(BreakJumpOut brk)
{
// We received a "break" from inside the "do" loop.
if(!Support.LabelMatch(brk.label, labels))
{
throw;
}
}
return result;
}
// Evaluate a "for" statement.
Eval(JFor)
{
Object result = Empty.Value;
Object temp;
if(init != null)
{
init.Eval(engine);
}
try
{
while(cond == null || Convert.ToBoolean(cond.Eval(engine)))
{
try
{
if(body != null)
{
temp = body.Eval(engine);
if(temp != Empty.Value)
{
result = temp;
}
}
}
catch(ContinueJumpOut cont)
{
// We received a "continue" from inside the
"for" loop.
if(!Support.LabelMatch(cont.label, labels))
{
throw;
}
}
if(incr != null)
{
incr.Eval(engine);
}
}
}
catch(BreakJumpOut brk)
{
// We received a "break" from inside the "for" loop.
if(!Support.LabelMatch(brk.label, labels))
{
throw;
}
}
return result;
}
// Evaluate a "for-in" statement.
Eval(JForIn)
{
// TODO
return Empty.Value;
}
// Evaluate a "switch" statement.
Eval(JSwitch)
{
Object value = expr.Eval(engine);
Object testValue;
Object result = Empty.Value;
JCompound node;
JNode child, defCase;
if(cases == null)
{
return result;
}
try
{
if(cases is JCase)
{
// Only has a single "case".
testValue = ((JCase)cases).expr.Eval(engine);
if(Equality.JScriptEquals(value, testValue))
{
result = ((JCase)cases).body.Eval(engine);
}
}
else if(cases is JDefault)
{
// Only has a "default" case, which we always execute.
result = ((JDefault)cases).body.Eval(engine);
}
else
{
// Search for an applicable case.
defCase = null;
node = (JCompound)cases;
do
{
if(node.stmt1 != null)
{
child = node.stmt1;
if(child is JCase)
{
testValue =
((JCase)child).expr.Eval(engine);
if(Equality.JScriptEquals(value, testValue))
{
return
((JCase)child).body.Eval(engine);
}
}
else
{
defCase = child;
}
}
if(node.stmt2 != null)
{
child = node.stmt2;
if(child is JCase)
{
testValue =
((JCase)child).expr.Eval(engine);
if(Equality.JScriptEquals(value, testValue))
{
return
((JCase)child).body.Eval(engine);
}
}
else
{
defCase = child;
}
}
if(node.stmt3 != null)
{
child = node.stmt3;
if(child is JCase)
{
testValue =
((JCase)child).expr.Eval(engine);
if(Equality.JScriptEquals(value, testValue))
{
return
((JCase)child).body.Eval(engine);
}
}
else
{
defCase = child;
}
}
if(node.stmt4 != null)
{
child = node.stmt4;
if(child is JCase)
{
testValue =
((JCase)child).expr.Eval(engine);
if(Equality.JScriptEquals(value, testValue))
{
return
((JCase)child).body.Eval(engine);
}
}
else
{
defCase = child;
}
}
node = node.next;
}
while(node != null);
if(defCase != null)
{
result = defCase.Eval(engine);
}
}
}
catch(BreakJumpOut brk)
{
// We received a "break" from inside the "switch" statement.
if(!Support.LabelMatch(brk.label, labels))
{
throw;
}
}
return result;
}
// Evaluate a "case" or "default" statement during fall-through execution.
Eval(JCase),
Eval(JDefault)
{
return body.Eval(engine);
}
// Evaluate a "fall through" statement, which jumps to the next
// case in a "switch" statement's body.
Eval(JFallThrough)
{
return stmt.Eval(engine);
}
// Evaluate a "continue" statement.
Eval(JContinue)
{
throw new ContinueJumpOut(label, context);
}
// Evaluate a "break" statement.
Eval(JBreak)
{
throw new BreakJumpOut(label, context);
}
// Evaluate a "return" statement, with no expression.
Eval(JReturn)
{
throw new ReturnJumpOut(null, context);
}
// Evaluate a "return" statement, with an expression.
Eval(JReturnExpr)
{
throw new ReturnJumpOut(expr.Eval(engine), context);
}
// Evaluate a "throw" statement.
Eval(JThrow)
{
throw Throw.JScriptThrow(expr.Eval(engine));
}
// Evaluate a "with" statement.
Eval(JWith)
{
Object result;
// Evaluate the expression to use inside the "with" block
// and push it onto the script object stack.
try
{
With.JScriptWith(expr.Eval(engine), engine);
}
catch(JScriptException e)
{
e.context = expr.context.MakeCopy();
throw e;
}
// Evaluate the body of the "with" block.
try
{
result = body.Eval(engine);
}
finally
{
engine.PopScriptObject();
}
return result;
}
// Evaluate a variable declaration statemnet.
Eval(JVarDecl)
{
// Get the current variable definition scope.
IActivationObject scope =
(IActivationObject)(engine.ScriptObjectStackTop());
// We can take a short-cut if the scope implements "IVariableAccess".
// This avoids creating unnecessary "FieldInfo" objects.
IVariableAccess varAccess = (scope as IVariableAccess);
if(varAccess != null)
{
if(initializer != null)
{
varAccess.SetVariable(name, initializer.Eval(engine));
}
return name;
}
// Get the field reference for the variable.
FieldInfo field = scope.GetLocalField(name);
if(field == null)
{
// Create a new field within the activation object with this
name.
// TODO
}
if(initializer != null)
{
// Set the variable to the specified initializer value.
// TODO
}
// Return the name of the variable as the node's final value.
return name;
}
// Evaluate a "try" statement.
Eval(JTry)
{
Object result = Empty.Value;
try
{
if(body != null)
{
result = body.Eval(engine);
}
}
catch(JScriptException e) // TODO: other exception types
{
if(catchName == null)
{
throw;
}
if(e.errorNumber == JSError.UncaughtException)
{
// Handle an object that was thrown by user JScript
code.
// TODO: push a scope and add "catchName" to it
try
{
catchClause.Eval(engine);
}
finally
{
// TODO: pop the scope
}
}
else
{
// TODO: convert runtime engine errors.
throw;
}
}
finally
{
if(finallyClause != null)
{
finallyClause.Eval(engine);
}
}
return result;
}
--- NEW FILE ---
# The build is done in "runtime", so cd up and use that Makefile.
all:
(cd ..;make)
clean:
(cd ..;make clean)
--- NEW FILE ---
/*
* ScriptBlock.cs - Lexical block containing script statements.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
// Dummy class for backwards-compatibility.
public sealed class ScriptBlock : AST
{
// Constructor.
internal ScriptBlock(JNode jnode) : base(jnode) {}
}; // class ScriptBlock
}; // namespace Microsoft.JScript
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Nodes .cvsignore,NONE,1.1 AST.cs,NONE,1.1 Block.cs,NONE,1.1 CodeBase.cs,NONE,1.1 Context.cs,NONE,1.1 JExpr.tc,NONE,1.1 JNode.tc,NONE,1.1 JStmt.tc,NONE,1.1 Makefile,NONE,1.1 ScriptBlock.cs,NONE,1.1,
Rhys Weatherley <address@hidden> <=