本文整理汇总了C#中ISeq.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ISeq.Add方法的具体用法?C# ISeq.Add怎么用?C# ISeq.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISeq
的用法示例。
在下文中一共展示了ISeq.Add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendFinalImport
// Take acccount of:
// - PassRootAsArgument
// - PassInstanceAsArgument
// - InlineParamsArray
private JST.Expression AppendFinalImport(JST.NameSupply nameSupply, JST.Identifier rootId, CST.AssemblyDef assemblyDef, CST.TypeDef typeDef, CST.MethodDef methodDef, JST.Expression script, ISeq<JST.Statement> body, IImSeq<JST.Expression> arguments)
{
var isInstanceMethod = !(methodDef.IsStatic || methodDef.IsConstructor);
var scriptExpectsRoot = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ImportAttributeRef,
attributeHelper.ThePassRootAsArgumentProperty,
true,
false,
ref scriptExpectsRoot);
var passInstAsArg = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ImportAttributeRef,
attributeHelper.ThePassInstanceAsArgumentProperty,
true,
false,
ref passInstAsArg);
var instanceIsThis = isInstanceMethod && !passInstAsArg;
var inlineParams = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ImportAttributeRef,
attributeHelper.TheInlineParamsArrayProperty,
true,
false,
ref inlineParams);
var lastArgIsParamsArray = methodDef.HasParamsArray(rootEnv) && inlineParams;
var funcScript = script as JST.FunctionExpression;
var nextArg = 0;
var instArg = default(JST.Expression);
if (instanceIsThis)
{
// Instance argument will be the first arg to 'call' or 'apply', or the target of a '.' call.
instArg = arguments[nextArg++];
if (lastArgIsParamsArray && !instArg.IsDuplicatable)
{
// Make sure instance argument is evaluated before the remaining arguments
var instId = nameSupply.GenSym();
body.Add(JST.Statement.Var(instId, instArg));
instArg = instId.ToE();
}
}
else
{
if (lastArgIsParamsArray)
instArg = new JST.NullExpression();
}
var knownArgs = 0;
var call = default(JST.Expression);
if (lastArgIsParamsArray)
{
// We mush build script args at runtime
var argsId = nameSupply.GenSym();
body.Add(JST.Statement.Var(argsId, new JST.ArrayLiteral()));
if (scriptExpectsRoot)
{
body.Add(JST.Statement.DotCall(argsId.ToE(), Constants.push, rootId.ToE()));
knownArgs++;
}
while (nextArg < arguments.Count - 1)
{
body.Add(JST.Statement.DotCall(argsId.ToE(), Constants.push, arguments[nextArg++]));
knownArgs++;
}
var arrArg = arguments[nextArg];
if (!arrArg.IsDuplicatable)
{
var arrId = nameSupply.GenSym();
body.Add(JST.Statement.Var(arrId, arrArg));
arrArg = arrId.ToE();
}
var iId = nameSupply.GenSym();
body.Add
(new JST.IfStatement
(JST.Expression.IsNotNull(arrArg),
new JST.Statements
(new JST.ForStatement
(new JST.ForVarLoopClause
(iId,
new JST.NumericLiteral(0),
new JST.BinaryExpression
(iId.ToE(),
JST.BinaryOp.LessThan,
JST.Expression.Dot(arrArg, Constants.length)),
//.........这里部分代码省略.........
示例2: EnsurePathExists
private void EnsurePathExists(ISeq<JST.Statement> statements, JST.Expression script, bool isStatic)
{
var path = JST.Expression.ExplodePath(script);
for (var i = isStatic ? 0 : 1; i < path.Count - 1; i++)
{
var prefixPath = new Seq<JST.PropertyName>();
for (var j = 0; j <= i; j++)
prefixPath.Add(path[j]);
var prefix = JST.Expression.Path(prefixPath);
if (i == 0)
{
var exId = new JST.Identifier("e");
#if !JSCRIPT_IS_CORRECT
statements.Add(JST.Statement.Var(exId));
#endif
statements.Add
(new JST.TryStatement
(new JST.Statements(new JST.ExpressionStatement(prefix)),
new JST.CatchClause
(exId, new JST.Statements(JST.Statement.Assignment(prefix, new JST.ObjectLiteral())))));
}
else if (!path[i].Value.Equals(Constants.prototype.Value, StringComparison.Ordinal))
statements.Add
(new JST.IfStatement
(JST.Expression.IsNull(prefix),
new JST.Statements(JST.Statement.Assignment(prefix, new JST.ObjectLiteral()))));
}
}
示例3: AppendFinalExport
// Take account of:
// - BindToPrototype
// - PassRootAsArgument
// - PassInstanceAsArgument
// - InlineParamsArray
private void AppendFinalExport(JST.NameSupply nameSupply, JST.Identifier rootId, CST.AssemblyDef assemblyDef, CST.TypeDef typeDef, CST.MethodDef methodDef, JST.Expression script, JST.Expression instance, ISeq<JST.Statement> body, AppendCallExported appendCallExported)
{
if (script == null)
throw new InvalidOperationException("expecting default script value");
var ctxt = CST.MessageContextBuilders.Member(env.Global, assemblyDef, typeDef, methodDef);
var isInstance = !methodDef.IsStatic && !methodDef.IsConstructor;
if (isInstance)
{
if (typeDef.Style is CST.ValueTypeStyle)
{
env.Log(new InvalidInteropMessage(ctxt, "cannot export instance methods from value types"));
throw new DefinitionException();
}
}
var inlineParams = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ExportAttributeRef,
attributeHelper.TheInlineParamsArrayProperty,
true,
false,
ref inlineParams);
var lastArgIsParamsArray = methodDef.HasParamsArray(rootEnv) && inlineParams;
var isPassRoot = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ExportAttributeRef,
attributeHelper.ThePassRootAsArgumentProperty,
true,
false,
ref isPassRoot);
var isProto = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ExportAttributeRef,
attributeHelper.TheBindToPrototypeProperty,
true,
false,
ref isProto);
var isPassInstance = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ExportAttributeRef,
attributeHelper.ThePassInstanceAsArgumentProperty,
true,
false,
ref isPassInstance);
var bindToInstance = isInstance && !isProto;
if (bindToInstance != (instance != null))
throw new InvalidOperationException("expecting instance");
var captureThis = isInstance && !isPassInstance;
var funcScript = script as JST.FunctionExpression;
// Build the function to export
var funcBody = new Seq<JST.Statement>();
var funcParameters = new Seq<JST.Identifier>();
var funcCallArgs = new Seq<JST.Expression>();
var funcArity = methodDef.Arity;
if ((methodDef.IsConstructor && !methodDef.IsStatic) || captureThis)
// unmanaged will not pass the instance
funcArity--;
if (lastArgIsParamsArray)
// managed params args will be extracted from remainder of unmanaged arguments
funcArity--;
if (captureThis)
funcCallArgs.Add(new JST.ThisExpression());
for (var i = 0; i < funcArity; i++)
{
var id = nameSupply.GenSym();
funcParameters.Add(id);
funcCallArgs.Add(id.ToE());
}
if (lastArgIsParamsArray)
{
var iId = nameSupply.GenSym();
//.........这里部分代码省略.........
示例4: BindUsage
public void BindUsage(ISeq<JST.Statement> statements, CST.Usage usage, TypePhase typePhase)
{
foreach (var kv in usage.Assemblies)
{
if (kv.Value > 1)
{
if (!boundAssemblies.ContainsKey(kv.Key))
{
var e = env.JSTHelpers.DefaultResolveAssembly(this, kv.Key);
if (e != null)
{
if (env.DebugMode)
statements.Add(new JST.CommentStatement(kv.Key.ToString()));
var id = NameSupply.GenSym();
statements.Add(JST.Statement.Var(id, e));
boundAssemblies.Add(kv.Key, id.ToE());
}
}
// else: use outer binding
}
// else: inline expression as need it
}
foreach (var kv in usage.Types)
{
if (kv.Value > 1)
{
var existing = default(ExpressionAndPhase);
var b = boundTypes.TryGetValue(kv.Key, out existing);
if (!b || typePhase > existing.Phase)
{
var e = env.JSTHelpers.DefaultResolveType(this, kv.Key, typePhase);
if (e != null)
{
if (env.DebugMode)
statements.Add(new JST.CommentStatement(kv.Key.ToString()));
var id = NameSupply.GenSym();
statements.Add(JST.Statement.Var(id, e));
var updated = new ExpressionAndPhase(id.ToE(), typePhase);
if (b)
boundTypes[kv.Key] = updated;
else
boundTypes.Add(kv.Key, updated);
}
}
// else: use outer binding
}
// else: inline expression as need it
}
}
示例5: ConsumeCommentStatement
private void ConsumeCommentStatement(ISeq<Statement> statements)
{
if (pendingComments != null)
{
statements.Add(new CommentStatement(pendingCommentsLoc, pendingComments.ToString()));
pendingComments = null;
pendingCommentsLoc = null;
}
}
示例6: AllEdgesFrom
private static void AllEdgesFrom(BasicBlock bb, ISeq<BBEdge> edges, Set<BasicBlock> visited)
{
if (!visited.Contains(bb))
{
visited.Add(bb);
foreach (var t in bb.Targets)
{
var edge = new BBEdge { Source = bb, Target = t };
edges.Add(edge);
AllEdgesFrom(t, edges, visited);
}
}
}
示例7: PreOrderFrom
private static void PreOrderFrom(BasicBlock bb, ISeq<BasicBlock> res, Set<BasicBlock> visited)
{
if (!visited.Contains(bb))
{
visited.Add(bb);
res.Add(bb);
foreach (var t in bb.Targets)
PreOrderFrom(t, res, visited);
}
}
示例8: AccumInstanceFields
// ----------------------------------------------------------------------
// Object helper methods in type structure
// ----------------------------------------------------------------------
private void AccumInstanceFields(CST.TypeEnvironment thisTypeEnv, ISeq<CST.FieldRef> fields)
{
if (thisTypeEnv.Type.Extends != null)
AccumInstanceFields(thisTypeEnv.Type.Extends.Enter(thisTypeEnv), fields);
foreach (var fieldDef in
thisTypeEnv.Type.Members.OfType<CST.FieldDef>().Where
(f => f.Invalid == null && f.IsUsed && !f.IsStatic))
fields.Add(new CST.FieldRef(thisTypeEnv.TypeRef, fieldDef.FieldSignature));
}
示例9: Emit
// ----------------------------------------------------------------------
// Entry point from TypeCompiler
// ----------------------------------------------------------------------
public void Emit(ISeq<JST.Statement> body, JST.Expression target)
{
if (env.BreakOnBreak &&
env.AttributeHelper.MethodHasAttribute(methEnv.Assembly, methEnv.Type, methEnv.Method, env.AttributeHelper.BreakAttributeRef, false, false))
System.Diagnostics.Debugger.Break();
var methodName = CST.CSTWriter.WithAppend(env.Global, CST.WriterStyle.Debug, methEnv.MethodRef.Append);
var methodSlot = env.GlobalMapping.ResolveMethodDefToSlot(methEnv.Assembly, methEnv.Type, methEnv.Method);
var method = Method(methodName);
switch (mode)
{
case MethodCompilationMode.SelfContained:
{
if (target != null)
throw new InvalidOperationException("not expecting target in self-contained mode");
var assmName = CST.CSTWriter.WithAppend
(env.Global, CST.WriterStyle.Uniform, methEnv.Assembly.Name.Append);
var typeSlot = env.GlobalMapping.ResolveTypeDefToSlot(methEnv.Assembly, methEnv.Type);
var func = new JST.FunctionExpression
(new Seq<JST.Identifier> { rootId, assemblyId, typeDefinitionId },
new JST.Statements(new JST.ReturnStatement(method)));
var methodLoader = new Seq<JST.Statement>();
if (env.DebugMode)
methodLoader.Add(new JST.CommentStatement(methodName));
methodLoader.Add
(JST.Statement.DotCall
(new JST.Identifier(env.Root).ToE(),
Constants.RootBindMethod,
new JST.StringLiteral(assmName),
new JST.StringLiteral(typeSlot),
new JST.BooleanLiteral(env.InteropManager.IsStatic(methEnv.Assembly, methEnv.Type, methEnv.Method)),
new JST.StringLiteral(methodSlot),
func));
var methodProgram = new JST.Program(new JST.Statements(methodLoader));
var methodFileName = Path.Combine
(env.OutputDirectory,
Path.Combine
(JST.Lexemes.StringToFileName(assmName),
Path.Combine(typeSlot, Path.Combine(methodSlot, Constants.MethodFileName))));
methodProgram.ToFile(methodFileName, env.PrettyPrint);
env.Log(new GeneratedJavaScriptFile("method '" + methEnv.MethodRef + "'", methodFileName));
break;
}
case MethodCompilationMode.DirectBind:
{
if (target == null)
throw new InvalidOperationException("expecting target in self-contained mode");
if (env.DebugMode)
body.Add(new JST.CommentStatement(methodName));
body.Add
(JST.Statement.Assignment(JST.Expression.Dot(target, new JST.Identifier(methodSlot)), method));
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
示例10: AddExceptionalExits
// ----------------------------------------------------------------------
// Effective control flow (accounting for exceptions)
// ----------------------------------------------------------------------
// Given block is within a try. What instructions within it may originate an exception?
private void AddExceptionalExits(ISeq<Instruction> exits, Instructions block)
{
foreach (var instruction in block.Body)
{
if (instruction.Flavor == InstructionFlavor.Try)
{
var tryi = (TryInstruction)instruction;
var addedBody = false;
foreach (var handler in tryi.Handlers)
{
if (handler.Flavor == HandlerFlavor.Filter)
throw new InvalidOperationException("filter block");
// An exception handler may always throw an exception of its own
AddExceptionalExits(exits, handler.Body);
if (handler.Flavor == HandlerFlavor.Catch)
{
// Its possible for the catch handler not to match the throw exception,
// thus exception will escape from try body
if (!addedBody)
{
AddExceptionalExits(exits, tryi.Body);
addedBody = true;
}
}
// else: Fault and Finally blocks always capture the exception, and continue with
// their own control flow. Thus no exception will escape the try body directly.
}
}
else
exits.Add(instruction);
}
}