本文整理汇总了C#中Node.GetLastChild方法的典型用法代码示例。如果您正苦于以下问题:C# Node.GetLastChild方法的具体用法?C# Node.GetLastChild怎么用?C# Node.GetLastChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node.GetLastChild方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindExpressionType
//.........这里部分代码省略.........
case Token.MOD:
case Token.BITOR:
case Token.BITXOR:
case Token.BITAND:
case Token.BITNOT:
case Token.LSH:
case Token.RSH:
case Token.URSH:
case Token.SUB:
case Token.POS:
case Token.NEG:
{
return Rhino.Optimizer.Optimizer.NumberType;
}
case Token.VOID:
{
// NYI: undefined type
return Rhino.Optimizer.Optimizer.AnyType;
}
case Token.FALSE:
case Token.TRUE:
case Token.EQ:
case Token.NE:
case Token.LT:
case Token.LE:
case Token.GT:
case Token.GE:
case Token.SHEQ:
case Token.SHNE:
case Token.NOT:
case Token.INSTANCEOF:
case Token.IN:
case Token.DEL_REF:
case Token.DELPROP:
{
// NYI: boolean type
return Rhino.Optimizer.Optimizer.AnyType;
}
case Token.STRING:
case Token.TYPEOF:
case Token.TYPEOFNAME:
{
// NYI: string type
return Rhino.Optimizer.Optimizer.AnyType;
}
case Token.NULL:
case Token.REGEXP:
case Token.ARRAYCOMP:
case Token.ARRAYLIT:
case Token.OBJECTLIT:
{
return Rhino.Optimizer.Optimizer.AnyType;
}
case Token.ADD:
{
// XXX: actually, we know it's not
// number, but no type yet for that
// if the lhs & rhs are known to be numbers, we can be sure that's
// the result, otherwise it could be a string.
Node child = n.GetFirstChild();
int lType = FindExpressionType(fn, child, varTypes);
int rType = FindExpressionType(fn, child.GetNext(), varTypes);
return lType | rType;
}
case Token.HOOK:
{
// we're not distinguishing strings yet
Node ifTrue = n.GetFirstChild().GetNext();
Node ifFalse = ifTrue.GetNext();
int ifTrueType = FindExpressionType(fn, ifTrue, varTypes);
int ifFalseType = FindExpressionType(fn, ifFalse, varTypes);
return ifTrueType | ifFalseType;
}
case Token.COMMA:
case Token.SETVAR:
case Token.SETNAME:
case Token.SETPROP:
case Token.SETELEM:
{
return FindExpressionType(fn, n.GetLastChild(), varTypes);
}
case Token.AND:
case Token.OR:
{
Node child = n.GetFirstChild();
int lType = FindExpressionType(fn, child, varTypes);
int rType = FindExpressionType(fn, child.GetNext(), varTypes);
return lType | rType;
}
}
return Rhino.Optimizer.Optimizer.AnyType;
}
示例2: VisitExpression
private void VisitExpression(Node node, int contextFlags)
{
int type = node.GetType();
Node child = node.GetFirstChild();
int savedStackDepth = stackDepth;
switch (type)
{
case Token.FUNCTION:
{
int fnIndex = node.GetExistingIntProp(Node.FUNCTION_PROP);
FunctionNode fn = scriptOrFn.GetFunctionNode(fnIndex);
// See comments in visitStatement for Token.FUNCTION case
if (fn.GetFunctionType() != FunctionNode.FUNCTION_EXPRESSION)
{
throw Kit.CodeBug();
}
AddIndexOp(Icode_CLOSURE_EXPR, fnIndex);
StackChange(1);
break;
}
case Token.LOCAL_LOAD:
{
int localIndex = GetLocalBlockRef(node);
AddIndexOp(Token.LOCAL_LOAD, localIndex);
StackChange(1);
break;
}
case Token.COMMA:
{
Node lastChild = node.GetLastChild();
while (child != lastChild)
{
VisitExpression(child, 0);
AddIcode(Icode_POP);
StackChange(-1);
child = child.GetNext();
}
// Preserve tail context flag if any
VisitExpression(child, contextFlags & ECF_TAIL);
break;
}
case Token.USE_STACK:
{
// Indicates that stack was modified externally,
// like placed catch object
StackChange(1);
break;
}
case Token.REF_CALL:
case Token.CALL:
case Token.NEW:
{
if (type == Token.NEW)
{
VisitExpression(child, 0);
}
else
{
GenerateCallFunAndThis(child);
}
int argCount = 0;
while ((child = child.GetNext()) != null)
{
VisitExpression(child, 0);
++argCount;
}
int callType = node.GetIntProp(Node.SPECIALCALL_PROP, Node.NON_SPECIALCALL);
if (type != Token.REF_CALL && callType != Node.NON_SPECIALCALL)
{
// embed line number and source filename
AddIndexOp(Icode_CALLSPECIAL, argCount);
AddUint8(callType);
AddUint8(type == Token.NEW ? 1 : 0);
AddUint16(lineNumber & unchecked((int)(0xFFFF)));
}
else
{
// Only use the tail call optimization if we're not in a try
// or we're not generating debug info (since the
// optimization will confuse the debugger)
if (type == Token.CALL && (contextFlags & ECF_TAIL) != 0 && !compilerEnv.IsGenerateDebugInfo() && !itsInTryFlag)
{
type = Icode_TAIL_CALL;
}
AddIndexOp(type, argCount);
}
// adjust stack
if (type == Token.NEW)
{
// new: f, args -> result
StackChange(-argCount);
}
else
{
// call: f, thisObj, args -> result
// ref_call: f, thisObj, args -> ref
//.........这里部分代码省略.........
示例3: CreateAssignment
//.........这里部分代码省略.........
break;
}
case Token.ASSIGN_BITXOR:
{
assignOp = Token.BITXOR;
break;
}
case Token.ASSIGN_BITAND:
{
assignOp = Token.BITAND;
break;
}
case Token.ASSIGN_LSH:
{
assignOp = Token.LSH;
break;
}
case Token.ASSIGN_RSH:
{
assignOp = Token.RSH;
break;
}
case Token.ASSIGN_URSH:
{
assignOp = Token.URSH;
break;
}
case Token.ASSIGN_ADD:
{
assignOp = Token.ADD;
break;
}
case Token.ASSIGN_SUB:
{
assignOp = Token.SUB;
break;
}
case Token.ASSIGN_MUL:
{
assignOp = Token.MUL;
break;
}
case Token.ASSIGN_DIV:
{
assignOp = Token.DIV;
break;
}
case Token.ASSIGN_MOD:
{
assignOp = Token.MOD;
break;
}
default:
{
throw Kit.CodeBug();
}
}
int nodeType = left.GetType();
switch (nodeType)
{
case Token.NAME:
{
Node op = new Node(assignOp, left, right);
Node lvalueLeft = Node.NewString(Token.BINDNAME, left.GetString());
return new Node(Token.SETNAME, lvalueLeft, op);
}
case Token.GETPROP:
case Token.GETELEM:
{
Node obj = left.GetFirstChild();
Node id = left.GetLastChild();
int type = nodeType == Token.GETPROP ? Token.SETPROP_OP : Token.SETELEM_OP;
Node opLeft = new Node(Token.USE_STACK);
Node op = new Node(assignOp, opLeft, right);
return new Node(type, obj, id, op);
}
case Token.GET_REF:
{
@ref = left.GetFirstChild();
CheckMutableReference(@ref);
Node opLeft = new Node(Token.USE_STACK);
Node op = new Node(assignOp, opLeft, right);
return new Node(Token.SET_REF_OP, @ref, op);
}
}
throw Kit.CodeBug();
}
示例4: CreateCallOrNew
private Node CreateCallOrNew(int nodeType, Node child)
{
int type = Node.NON_SPECIALCALL;
if (child.GetType() == Token.NAME)
{
string name = child.GetString();
if (name.Equals("eval"))
{
type = Node.SPECIALCALL_EVAL;
}
else
{
if (name.Equals("With"))
{
type = Node.SPECIALCALL_WITH;
}
}
}
else
{
if (child.GetType() == Token.GETPROP)
{
string name = child.GetLastChild().GetString();
if (name.Equals("eval"))
{
type = Node.SPECIALCALL_EVAL;
}
}
}
Node node = new Node(nodeType, child);
if (type != Node.NON_SPECIALCALL)
{
// Calls to these functions require activation objects.
SetRequiresActivation();
node.PutIntProp(Node.SPECIALCALL_PROP, type);
}
return node;
}
示例5: CreateUnary
private Node CreateUnary(int nodeType, Node child)
{
int childType = child.GetType();
switch (nodeType)
{
case Token.DELPROP:
{
Node n;
if (childType == Token.NAME)
{
// Transform Delete(Name "a")
// to Delete(Bind("a"), String("a"))
child.SetType(Token.BINDNAME);
Node left = child;
Node right = Node.NewString(child.GetString());
n = new Node(nodeType, left, right);
}
else
{
if (childType == Token.GETPROP || childType == Token.GETELEM)
{
Node left = child.GetFirstChild();
Node right = child.GetLastChild();
child.RemoveChild(left);
child.RemoveChild(right);
n = new Node(nodeType, left, right);
}
else
{
if (childType == Token.GET_REF)
{
Node @ref = child.GetFirstChild();
child.RemoveChild(@ref);
n = new Node(Token.DEL_REF, @ref);
}
else
{
// Always evaluate delete operand, see ES5 11.4.1 & bug #726121
n = new Node(nodeType, new Node(Token.TRUE), child);
}
}
}
return n;
}
case Token.TYPEOF:
{
if (childType == Token.NAME)
{
child.SetType(Token.TYPEOFNAME);
return child;
}
break;
}
case Token.BITNOT:
{
if (childType == Token.NUMBER)
{
int value = ScriptRuntime.ToInt32(child.GetDouble());
child.SetDouble(~value);
return child;
}
break;
}
case Token.NEG:
{
if (childType == Token.NUMBER)
{
child.SetDouble(-child.GetDouble());
return child;
}
break;
}
case Token.NOT:
{
int status = IsAlwaysDefinedBoolean(child);
if (status != 0)
{
int type;
if (status == ALWAYS_TRUE_BOOLEAN)
{
type = Token.FALSE;
}
else
{
type = Token.TRUE;
}
if (childType == Token.TRUE || childType == Token.FALSE)
{
child.SetType(type);
return child;
}
return new Node(type);
}
break;
}
}
//.........这里部分代码省略.........
示例6: CreateForIn
/// <summary>Generate IR for a for..in loop.</summary>
/// <remarks>Generate IR for a for..in loop.</remarks>
private Node CreateForIn(int declType, Node loop, Node lhs, Node obj, Node body, bool isForEach)
{
int destructuring = -1;
int destructuringLen = 0;
Node lvalue;
int type = lhs.GetType();
if (type == Token.VAR || type == Token.LET)
{
Node kid = lhs.GetLastChild();
int kidType = kid.GetType();
if (kidType == Token.ARRAYLIT || kidType == Token.OBJECTLIT)
{
type = destructuring = kidType;
lvalue = kid;
destructuringLen = 0;
if (kid is ArrayLiteral)
{
destructuringLen = ((ArrayLiteral)kid).GetDestructuringLength();
}
}
else
{
if (kidType == Token.NAME)
{
lvalue = Node.NewString(Token.NAME, kid.GetString());
}
else
{
ReportError("msg.bad.for.in.lhs");
return null;
}
}
}
else
{
if (type == Token.ARRAYLIT || type == Token.OBJECTLIT)
{
destructuring = type;
lvalue = lhs;
destructuringLen = 0;
if (lhs is ArrayLiteral)
{
destructuringLen = ((ArrayLiteral)lhs).GetDestructuringLength();
}
}
else
{
lvalue = MakeReference(lhs);
if (lvalue == null)
{
ReportError("msg.bad.for.in.lhs");
return null;
}
}
}
Node localBlock = new Node(Token.LOCAL_BLOCK);
int initType = isForEach ? Token.ENUM_INIT_VALUES : (destructuring != -1 ? Token.ENUM_INIT_ARRAY : Token.ENUM_INIT_KEYS);
Node init = new Node(initType, obj);
init.PutProp(Node.LOCAL_BLOCK_PROP, localBlock);
Node cond = new Node(Token.ENUM_NEXT);
cond.PutProp(Node.LOCAL_BLOCK_PROP, localBlock);
Node id = new Node(Token.ENUM_ID);
id.PutProp(Node.LOCAL_BLOCK_PROP, localBlock);
Node newBody = new Node(Token.BLOCK);
Node assign;
if (destructuring != -1)
{
assign = CreateDestructuringAssignment(declType, lvalue, id);
if (!isForEach && (destructuring == Token.OBJECTLIT || destructuringLen != 2))
{
// destructuring assignment is only allowed in for..each or
// with an array type of length 2 (to hold key and value)
ReportError("msg.bad.for.in.destruct");
}
}
else
{
assign = SimpleAssignment(lvalue, id);
}
newBody.AddChildToBack(new Node(Token.EXPR_VOID, assign));
newBody.AddChildToBack(body);
loop = CreateLoop((Jump)loop, LOOP_WHILE, newBody, cond, null, null);
loop.AddChildToFront(init);
if (type == Token.VAR || type == Token.LET)
{
loop.AddChildToFront(lhs);
}
localBlock.AddChildToBack(loop);
return localBlock;
}
示例7: InitFunction
private Node InitFunction(FunctionNode fnNode, int functionIndex, Node statements, int functionType)
{
fnNode.SetFunctionType(functionType);
fnNode.AddChildToBack(statements);
int functionCount = fnNode.GetFunctionCount();
if (functionCount != 0)
{
// Functions containing other functions require activation objects
fnNode.SetRequiresActivation();
}
if (functionType == FunctionNode.FUNCTION_EXPRESSION)
{
Name name = fnNode.GetFunctionName();
if (name != null && name.Length() != 0 && fnNode.GetSymbol(name.GetIdentifier()) == null)
{
// A function expression needs to have its name as a
// variable (if it isn't already allocated as a variable).
// See ECMA Ch. 13. We add code to the beginning of the
// function to initialize a local variable of the
// function's name to the function value, but only if the
// function doesn't already define a formal parameter, var,
// or nested function with the same name.
fnNode.PutSymbol(new Symbol(Token.FUNCTION, name.GetIdentifier()));
Node setFn = new Node(Token.EXPR_VOID, new Node(Token.SETNAME, Node.NewString(Token.BINDNAME, name.GetIdentifier()), new Node(Token.THISFN)));
statements.AddChildrenToFront(setFn);
}
}
// Add return to end if needed.
Node lastStmt = statements.GetLastChild();
if (lastStmt == null || lastStmt.GetType() != Token.RETURN)
{
statements.AddChildToBack(new Node(Token.RETURN));
}
Node result = Node.NewString(Token.FUNCTION, fnNode.GetName());
result.PutIntProp(Node.FUNCTION_PROP, functionIndex);
return result;
}