本文整理汇总了C#中Seq.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Seq.Add方法的具体用法?C# Seq.Add怎么用?C# Seq.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Seq
的用法示例。
在下文中一共展示了Seq.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildTypeExpression
// Complete a first-kinded type structure. If type definition is higher kinded, this will
// complete an instance of the type at the type arguments. Otherwise, this will complete
// the type definition itself.
private void BuildTypeExpression(Seq<JST.Statement> body, JST.Expression lhs)
{
TypeCompEnv.BindUsage(body, CollectPhase1Usage(), TypePhase.Id);
// TODO: Replace with prototype
body.Add(JST.Statement.DotCall(RootId.ToE(), Constants.RootSetupTypeDefaults, TypeId.ToE()));
EmitBaseAndSupertypes(body, lhs);
EmitDefaultConstructor(body, lhs);
EmitMemberwiseClone(body, lhs);
EmitClone(body, lhs);
EmitDefaultValue(body, lhs);
EmitStaticMethods(body, lhs);
EmitConstructObjectAndInstanceMethods(body, lhs);
EmitVirtualAndInterfaceMethodRedirectors(body, lhs);
EmitSetupType(body, lhs);
EmitUnbox(body, lhs);
EmitBox(body, lhs);
EmitUnboxAny(body, lhs);
EmitConditionalDeref(body, lhs);
EmitIsValue(body, lhs);
EmitEquals(body, lhs);
EmitHash(body, lhs);
EmitInterop(body, lhs);
}
示例2: Emit
public void Emit()
{
if (Trace.Flavor == TraceFlavor.Remainder)
{
foreach (var kv in Trace.AssemblyMap)
{
var compiler = new AssemblyCompiler(this, kv.Value);
compiler.Emit(null);
}
}
else
{
var rootEnv = Env.Global.Environment();
var body = new Seq<JST.Statement>();
body.Add(JST.Statement.Var(RootId, new JST.Identifier(Env.Root).ToE()));
foreach (var nm in rootEnv.AllLoadedAssembliesInLoadOrder().Where(Trace.AssemblyMap.ContainsKey))
{
var compiler = new AssemblyCompiler(this, Trace.AssemblyMap[nm]);
compiler.Emit(body);
}
var program = new JST.Program
(new JST.Statements
(new JST.ExpressionStatement
(new JST.StatementsPseudoExpression(new JST.Statements(body), null))));
var fileName = Path.Combine(Env.OutputDirectory, Trace.Name + ".js");
program.ToFile(fileName, Env.PrettyPrint);
Env.Log(new GeneratedJavaScriptFile("trace '" + Trace.Name + "'", fileName));
}
}
示例3: CallContext
public CallContext(CompilationEnvironment outerCompEnv, CompilationEnvironment inlinedCompEnv, IImSeq<Expression> arguments)
{
var paramMap = new Map<JST.Identifier, int>();
for (var i = 0; i < inlinedCompEnv.Method.Arity; i++)
paramMap.Add(inlinedCompEnv.ValueParameterIds[i], i);
Parameters = paramMap;
var argumentEffects = new Seq<JST.Effects>(inlinedCompEnv.Method.Arity);
SeenParameters = new Seq<bool?>(inlinedCompEnv.Method.Arity);
AllArgumentEffects = JST.Effects.Bottom;
var allReadOnly = true;
foreach (var e in arguments)
{
var fxCtxt = new JST.EffectsContext(null);
e.AccumEffects(fxCtxt, null, null);
argumentEffects.Add(fxCtxt.AccumEffects);
AllArgumentEffects = AllArgumentEffects.Lub(fxCtxt.AccumEffects);
if (!fxCtxt.AccumEffects.IsReadOnly)
allReadOnly = false;
SeenParameters.Add(e.IsValue(outerCompEnv) ? default(bool?) : false);
}
ArgumentEffects = argumentEffects;
AllReadOnly = allReadOnly;
IsOk = true;
}
示例4: TopologicalAllDeps
internal void TopologicalAllDeps(Global global, AssemblyDef assemblyDef, TypeDef typeDef, Set<QualifiedMemberName> visitedMemberDefs, Seq<QualifiedMemberName> sortedMemberDefs)
{
var self = QualifiedMemberName(global, assemblyDef, typeDef);
if (visitedMemberDefs.Contains(self))
return;
visitedMemberDefs.Add(self);
if (usedTypes == null)
return;
foreach (var r in usedTypes)
{
var usedAssemblyDef = default(AssemblyDef);
var usedTypeDef = default(TypeDef);
if (r.PrimTryResolve(global, out usedAssemblyDef, out usedTypeDef))
usedTypeDef.UsedBy(self);
}
foreach (var r in usedMembers)
{
var usedAssemblyDef = default(AssemblyDef);
var usedTypeDef = default(TypeDef);
var usedMemberDef = default(MemberDef);
if (r.PrimTryResolve(global, out usedAssemblyDef, out usedTypeDef, out usedMemberDef))
{
usedMemberDef.UsedBy(self);
usedMemberDef.TopologicalAllDeps
(global, usedAssemblyDef, usedTypeDef, visitedMemberDefs, sortedMemberDefs);
}
}
sortedMemberDefs.Add(self);
}
示例5: LoopClause
private LoopClause LoopClause()
{
var loc = Only("loop clause", "'('", InputElementTag.LParen);
if (Current.Tag == InputElementTag.Semicolon)
{
Consume();
var condition = default(Expression);
if (Current.Tag != InputElementTag.Semicolon)
condition = Expression(false);
Only("loop clause", "';'", InputElementTag.Semicolon);
if (condition != null)
condition = ConsumeCommentExpression(condition);
var increment = default(Expression);
if (Current.Tag != InputElementTag.RParen)
increment = Expression(false);
loc = loc.Union(Only("loop clause", "')'", InputElementTag.RParen));
if (increment != null)
increment = ConsumeCommentExpression(increment);
return new ForLoopClause(loc, null, condition, increment);
}
else if (Current.Tag == InputElementTag.Var)
{
Consume();
var vd = VariableDeclaration(true);
if (Current.Tag == InputElementTag.In)
{
Consume();
var collection = Expression(false);
loc = loc.Union(Only("loop clause", "')'", InputElementTag.RParen));
collection = ConsumeCommentExpression(collection);
return new ForEachVarLoopClause(loc, vd, collection);
}
else
{
var iterationVariables = new Seq<VariableDeclaration>();
iterationVariables.Add(vd);
while (Current.Tag == InputElementTag.Comma)
{
Consume();
iterationVariables.Add(VariableDeclaration(true));
}
Only("loop clause", "';'", InputElementTag.Semicolon);
var condition = default(Expression);
if (Current.Tag != InputElementTag.Semicolon)
condition = Expression(false);
Only("loop clause", "';'", InputElementTag.Semicolon);
if (condition != null)
condition = ConsumeCommentExpression(condition);
var increment = default(Expression);
if (Current.Tag != InputElementTag.RParen)
increment = Expression(false);
loc = loc.Union(Only("loop clause", "')'", InputElementTag.RParen));
if (increment != null)
increment = ConsumeCommentExpression(increment);
return new ForVarLoopClause(loc, iterationVariables, condition, increment);
}
}
else
{
var isLHS = true;
var i = Expression(true, ref isLHS);
if (Current.Tag == InputElementTag.Semicolon)
{
var initializer = i;
Consume();
initializer = ConsumeCommentExpression(initializer);
var condition = default(Expression);
if (Current.Tag != InputElementTag.Semicolon)
condition = Expression(false);
Only("loop clause", "';'", InputElementTag.Semicolon);
if (condition != null)
condition = ConsumeCommentExpression(condition);
var increment = default(Expression);
if (Current.Tag != InputElementTag.RParen)
increment = Expression(false);
loc = loc.Union(Only("loop clause", "')'", InputElementTag.RParen));
if (increment != null)
increment = ConsumeCommentExpression(increment);
return new ForLoopClause(loc, initializer, condition, increment);
}
else if (isLHS)
{
Only("loop clause", "'in'", InputElementTag.In);
var iterationVariable = i;
iterationVariable = ConsumeCommentExpression(iterationVariable);
var collection = Expression(false);
loc = loc.Union(Only("loop clause", "')'", InputElementTag.RParen));
collection = ConsumeCommentExpression(collection);
return new ForEachLoopClause(loc, iterationVariable, collection);
}
else
throw MsgError("loop clause", "syntax error");
}
}
示例6: Loops
public static ISeq<BBLoop> Loops(BasicBlock root)
{
var res = new Seq<BBLoop>();
var backEdges = BackEdges(root);
foreach (var backEdge in backEdges)
{
var body = new Set<BasicBlock> { backEdge.Target };
ReachableFrom(backEdge.Source, body);
res.Add(new BBLoop(backEdge.Target, backEdge.Source, body, null));
}
return res;
}
示例7: Emit
public void Emit()
{
var assm = typeof (RuntimeCompiler).Assembly;
var res = "Microsoft.LiveLabs.JavaScript.IL2JS." + Constants.RuntimeFileName;
var runtime = default(JST.Program);
using (var runtimeStream = assm.GetManifestResourceStream(res))
{
if (runtimeStream == null)
throw new InvalidOperationException("unable to find runtime resource");
runtime = JST.Program.FromStream(Constants.RuntimeFileName, runtimeStream, true);
}
var mode = default(string);
switch (env.CompilationMode)
{
case CompilationMode.Plain:
mode = "plain";
break;
case CompilationMode.Collecting:
mode = "collecting";
break;
case CompilationMode.Traced:
mode = "traced";
break;
default:
throw new ArgumentOutOfRangeException();
}
var body = default(ISeq<JST.Statement>);
if (env.DebugMode)
{
body = new Seq<JST.Statement>();
body.Add
(JST.Statement.Var(Constants.DebugLevel, new JST.NumericLiteral(env.DebugLevel)));
body.Add(JST.Statement.Var(Constants.DebugId, new JST.BooleanLiteral(true)));
body.Add(JST.Statement.Var(Constants.ModeId, new JST.StringLiteral(mode)));
body.Add(JST.Statement.Var(Constants.SafeId, new JST.BooleanLiteral(env.SafeInterop)));
foreach (var s in runtime.Body.Body)
body.Add(s);
}
else
{
// Simplify
var simpCtxt =
new JST.SimplifierContext(true, env.DebugMode, new JST.NameSupply(Constants.Globals), null).
InFreshStatements();
simpCtxt.Bind(Constants.DebugId, new JST.BooleanLiteral(false));
simpCtxt.Bind(Constants.ModeId, new JST.StringLiteral(mode));
simpCtxt.Bind(Constants.SafeId, new JST.BooleanLiteral(env.SafeInterop));
simpCtxt.Add(JST.Statement.Var(Constants.DebugLevel, new JST.NumericLiteral(env.DebugLevel)));
runtime.Body.Simplify(simpCtxt, EvalTimes.Bottom, false);
body = simpCtxt.Statements;
}
var opts = new OrdMap<JST.Identifier, JST.Expression>();
var mscorlibName = new JST.StringLiteral
(CST.CSTWriter.WithAppend(env.Global, CST.WriterStyle.Uniform, env.Global.MsCorLibName.Append));
opts.Add(Constants.SetupMscorlib, mscorlibName);
var target = default(string);
switch (env.Target)
{
case Target.Browser:
target = "browser";
break;
case Target.CScript:
target = "cscript";
break;
default:
throw new ArgumentOutOfRangeException();
}
opts.Add(Constants.SetupTarget, new JST.StringLiteral(target));
var loadPaths = env.LoadPaths.Select<string, JST.Expression>(FixupPath).ToSeq();
if (loadPaths.Count == 0)
loadPaths.Add(new JST.StringLiteral(""));
opts.Add(Constants.SetupSearchPaths, new JST.ArrayLiteral(loadPaths));
if (env.DebugMode)
body.Add(new JST.CommentStatement("Setup runtime"));
var rootId = new JST.Identifier(env.Root);
body.Add(JST.Statement.Var(rootId, new JST.ObjectLiteral()));
body.Add(JST.Statement.Call(Constants.NewRuntime.ToE(), rootId.ToE(), new JST.ObjectLiteral(opts)));
var program = new JST.Program(new JST.Statements(body));
var runtimeFileName = Path.Combine(env.OutputDirectory, Constants.RuntimeFileName);
program.ToFile(runtimeFileName, env.PrettyPrint);
env.Log(new GeneratedJavaScriptFile("runtime", runtimeFileName));
}
示例8: PrefixName
// Imports:
// - instance methods: no qualification
// - static methods & constructors: add qualification
// Exports:
// - instance methods, not prototype bound: no qualification
// - instance methods, prototype bound: add qualification and 'prototype'
// - static methods & constructors: add qualification
private JST.Expression PrefixName(CST.AssemblyDef assemblyDef, CST.TypeDef typeDef, CST.MethodDef methodDef, JST.Expression script, bool isExport)
{
if (script != null && script is JST.FunctionExpression)
return script;
var isNonInstance = methodDef.IsStatic || methodDef.IsConstructor;
var qual = default(Qualification);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.NamingAttributeRef,
attributeHelper.TheQualificationProperty,
true,
false,
ref qual);
var bindToProto = default(bool);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.ExportAttributeRef,
attributeHelper.TheBindToPrototypeProperty,
true,
false,
ref bindToProto);
var isProto = isExport && bindToProto;
var path = new Seq<JST.PropertyName>();
if (script == null && !methodDef.IsStatic && methodDef.IsConstructor && qual == Qualification.None)
qual = Qualification.Type;
if (!isExport && !isNonInstance && qual != Qualification.None)
qual = Qualification.None;
if (isExport && !isNonInstance && !isProto && qual != Qualification.None)
qual = Qualification.None;
if (isExport && !isNonInstance && isProto && qual == Qualification.None)
qual = Qualification.Type;
if (isNonInstance)
{
var global = default(JST.Expression);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.NamingAttributeRef,
attributeHelper.TheGlobalObjectProperty,
true,
false,
ref global);
if (global != null)
{
if (global is JST.FunctionExpression)
{
var ctxt = CST.MessageContextBuilders.Member(env.Global, assemblyDef, typeDef, methodDef);
env.Log(new InvalidInteropMessage(ctxt, "global object expression cannot be a function"));
throw new DefinitionException();
}
foreach (var p in JST.Expression.ExplodePath(global))
path.Add(p);
}
}
if (qual == Qualification.Full)
{
var nm = typeDef.EffectiveName(env.Global);
if (nm.Namespace.Length > 0)
{
var nsCasing = default(Casing);
attributeHelper.GetValueFromMethod
(assemblyDef,
typeDef,
methodDef,
attributeHelper.NamingAttributeRef,
attributeHelper.TheNamespaceCasingProperty,
true,
false,
ref nsCasing);
foreach (var n in nm.Namespace.Split('.'))
path.Add(new JST.PropertyName(Recase(n, nsCasing)));
}
}
if (qual == Qualification.Full || qual == Qualification.Type)
{
var tnCasing = default(Casing);
attributeHelper.GetValueFromType
(assemblyDef,
typeDef,
//.........这里部分代码省略.........
示例9: OutermostTryBlocks
// Return all the exception clauses which:
// - Start at given instruction index
// - Are not in the current context
// - Finish at the same instruction index
// However:
// - Only attempt to group catch clauses
// Return null if no new exception clauses start at given instruction
public ISeq<PE.ExceptionHandlingClause> OutermostTryBlocks(int i)
{
var offset = Instructions[i].Offset;
if (TryOffsets.Contains(offset))
{
// Clauses are in inner-to-outer order, look for the outermost
var last = -1;
for (var j = Handlers.Count - 1; j >= 0; j--)
{
var ehc = Handlers[j];
if (offset == ehc.TryOffset && !Within(ehc))
{
last = j;
break;
}
}
if (last >= 0)
{
var res = new Seq<PE.ExceptionHandlingClause>();
var first = last - 1;
while (first >= 0 && Handlers[first].TryOffset == Handlers[last].TryOffset &&
Handlers[first].TryLength == Handlers[last].TryLength &&
Handlers[first].Flags == PE.CorILExceptionClause.Exception &&
Handlers[last].Flags == PE.CorILExceptionClause.Exception)
first--;
first++;
for (var j = first; j <= last; j++)
res.Add(Handlers[j]);
return res;
}
else
return null;
}
else
return null;
}
示例10: 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()))));
}
}
示例11: FinalExportInfo
// Take account of:
// - BindToPrototype
// - PassRootAsArgument
// - PassInstanceAsArgument
// - InlineParamsArray
private ExportMethodInfo FinalExportInfo(MessageContext ctxt, Func<JST.Identifier> gensym, JST.Identifier rootId, CCI.Method methodDefn, JST.Expression script)
{
if (script == null)
throw new InvalidOperationException("expecting default script value");
var isInstance = !methodDefn.IsStatic && !(methodDefn is CCI.InstanceInitializer);
if (isInstance)
{
var declType = methodDefn.DeclaringType;
if (declType.IsValueType)
{
env.Log(new InvalidInteropMessage
(RewriterMsgContext.Method(ctxt, methodDefn), "cannot export instance methods from value types"));
throw new DefinitionException();
}
}
var lastArgIsParamsArray = LastArgIsParamsArray(ctxt, methodDefn) &&
interopTypes.GetValue
(ctxt,
methodDefn,
env.ExportAttributeType,
interopTypes.TheInlineParamsArrayProperty);
var isPassRoot = interopTypes.GetValue
(ctxt, methodDefn, env.ExportAttributeType, interopTypes.ThePassRootAsArgumentProperty);
var isProto = interopTypes.GetValue
(ctxt, methodDefn, env.ExportAttributeType, interopTypes.TheBindToPrototypeProperty);
var isPassInstance = interopTypes.GetValue
(ctxt, methodDefn, env.ExportAttributeType, interopTypes.ThePassInstanceAsArgumentProperty);
var bindToInstance = isInstance && !isProto;
var captureThis = isInstance && !isPassInstance;
var expectedScriptArity = (isPassRoot ? 1 : 0) + (bindToInstance ? 1 : 0) + 1;
CheckScriptArity(ctxt, methodDefn, script, expectedScriptArity);
var function = default(JST.FunctionExpression);
if (gensym != null)
{
var parameters = new Seq<JST.Identifier>();
var body = new Seq<JST.Statement>();
var callArgs = new Seq<JST.Expression>();
if (isPassRoot)
callArgs.Add(rootId.ToE());
var instArgId = default(JST.Identifier);
if (bindToInstance)
{
instArgId = gensym();
parameters.Add(instArgId);
callArgs.Add(instArgId.ToE());
}
var funcArgId = gensym();
parameters.Add(funcArgId);
if (captureThis || lastArgIsParamsArray)
{
var innerParameters = new Seq<JST.Identifier>();
var innerBody = new Seq<JST.Statement>();
var innerArgs = new Seq<JST.Expression>();
var methodArity = Arity(methodDefn);
for (var i = 0; i < methodArity; i++)
{
if (i == 0 && captureThis)
innerArgs.Add(new JST.ThisExpression());
else if (i == methodArity - 1 && lastArgIsParamsArray)
{
var iId = gensym();
var arrId = gensym();
innerBody.Add(JST.Statement.Var(arrId, new JST.ArrayLiteral()));
innerBody.Add
(new JST.ForStatement
(new JST.ForVarLoopClause
(iId,
new JST.NumericLiteral(methodArity - 1),
new JST.BinaryExpression
(iId.ToE(),
JST.BinaryOp.LessThan,
JST.Expression.Dot(Constants.arguments.ToE(), Constants.length)),
new JST.UnaryExpression(iId.ToE(), JST.UnaryOp.PostIncrement)),
new JST.Statements(JST.Statement.DotCall
(arrId.ToE(),
Constants.push,
new JST.IndexExpression(Constants.arguments.ToE(), iId.ToE())))));
innerArgs.Add(arrId.ToE());
}
else
{
var innerArgId = gensym();
innerParameters.Add(innerArgId);
innerArgs.Add(innerArgId.ToE());
}
}
if (ReturnType(methodDefn) == null)
{
//.........这里部分代码省略.........
示例12: Load
public void Load(IImSeq<string> fileNames, out CCI.AssemblyNode mscorlib, out CCI.AssemblyNode jsTypes)
{
foreach (var fileName in fileNames)
{
var canonicalFileName = CanonicalFileName(fileName);
if (fileNameToAssembly.ContainsKey(canonicalFileName))
{
env.Log(new DuplicateAssemblyFileNameMessage(fileName, canonicalFileName));
throw new ExitException();
}
else
fileNameToAssembly.Add(canonicalFileName, null);
}
// ----------------------------------------
// Which assembly should we use for mscorlib and JSTypes?
// ----------------------------------------
var mscorlibCanonicalName = default(string);
var jsTypesCanonicalName = default(string);
foreach (var kv in fileNameToAssembly)
{
var baseName = Path.GetFileNameWithoutExtension(kv.Key);
if (baseName.ToLower().Contains(Constants.MsCorLibSimpleName.ToLower()))
{
if (mscorlibCanonicalName != null)
{
env.Log(new DuplicateSpecialAssemblyMessage(Constants.MsCorLibSimpleName, mscorlibCanonicalName, kv.Key));
throw new ExitException();
}
mscorlibCanonicalName = kv.Key;
}
else if (baseName.ToLower().Contains(Constants.JSTypesSimpleName.ToLower()))
{
if (jsTypesCanonicalName != null)
{
env.Log(new DuplicateSpecialAssemblyMessage(Constants.JSTypesSimpleName, jsTypesCanonicalName, kv.Key));
throw new ExitException();
}
jsTypesCanonicalName = kv.Key;
}
}
if (mscorlibCanonicalName == null)
{
env.Log(new MissingSpecialAssemblyMessage(Constants.MsCorLibSimpleName));
throw new ExitException();
}
if (jsTypesCanonicalName == null)
{
env.Log(new MissingSpecialAssemblyMessage(Constants.JSTypesSimpleName));
throw new ExitException();
}
// ----------------------------------------
// Initialize CCI, which will implicitly load mscorlib
// ----------------------------------------
var frameworkDir = Path.GetDirectoryName(mscorlibCanonicalName);
if (!Directory.Exists(frameworkDir))
{
env.Log(new UnloadableAssemblyMessage(frameworkDir, "directory does not exist"));
throw new ExitException();
}
// These special CCI assemblies, and mscorlib, will be picked up from the framework directory
CCI.SystemDataAssemblyLocation.Location = null;
CCI.SystemXmlAssemblyLocation.Location = null;
CCI.TargetPlatform.SetToV2(frameworkDir);
// At this point we could "fixup" CCI's hard-wired system assembly references:
//
// foreach (var asmRefs in CCI.TargetPlatform.AssemblyReferenceFor.GetEnumerator())
// {
// var asmRef = (CCI.AssemblyReference)asmRefs.Value;
// asmRef.Location = <the right place>;
// }
// SystemAssemblyLocation.Location = <the right place>;
// SystemXmlAssemblyLocation.Location = <the right place>;
//
// But so far that doesn't seem necessary
CCI.SystemTypes.Initialize(false, true, ResolveReference);
// ----------------------------------------
// Account for mscorlib being loaded
// ----------------------------------------
mscorlib = CCI.SystemTypes.SystemAssembly;
if (mscorlib == null || mscorlib.Directory == null)
{
env.Log(new UnloadableAssemblyMessage(frameworkDir, "cannot load mscorlib"));
throw new ExitException();
}
env.Log(new FoundSpecialAssemblyMessage(Constants.MsCorLibSimpleName, mscorlib.StrongName));
fileNameToAssembly[mscorlibCanonicalName] = mscorlib;
strongNameToInfo.Add
(mscorlib.StrongName, new Info { Assembly = mscorlib, FileName = mscorlibCanonicalName });
// ----------------------------------------
// Load the remaining registered assemblies
//.........这里部分代码省略.........
示例13: ImportInfo
public ImportMethodInfo ImportInfo(MessageContext ctxt, Func<JST.Identifier> gensym, JST.Identifier rootId, CCI.Method methodDefn)
{
if (!IsImported(ctxt, methodDefn))
return null;
if (gensym != null)
CheckParameterAndReturnTypesAreImportableExportable(ctxt, methodDefn);
var methodArity = Arity(methodDefn);
var script = interopTypes.GetValue(ctxt, methodDefn, env.ImportAttributeType, interopTypes.TheScriptProperty);
if (methodDefn is CCI.InstanceInitializer)
{
// XREF1171
// Constructor
if (script == null)
{
switch (
interopTypes.GetValue
(ctxt, methodDefn, env.ImportAttributeType, interopTypes.TheCreationProperty))
{
case Creation.Constructor:
script = PrefixName(ctxt, methodDefn, null, false);
break;
case Creation.Object:
if (methodArity > 0)
{
env.Log(new InvalidInteropMessage
(RewriterMsgContext.Method(ctxt, methodDefn),
"imported constructors for object literals cannot have arguments"));
throw new DefinitionException();
}
script = Constants.Object.ToE();
break;
case Creation.Array:
script = Constants.Array.ToE();
break;
default:
throw new ArgumentOutOfRangeException();
}
return FinalImportScript(ctxt, gensym, rootId, methodDefn, script, true);
}
else if (script is JST.FunctionExpression)
return FinalImportScript(ctxt, gensym, rootId, methodDefn, script, false);
else
{
script = PrefixName(ctxt, methodDefn, script, false);
return FinalImportScript(ctxt, gensym, rootId, methodDefn, script, true);
}
}
else
{
if (methodDefn.DeclaringMember != null)
{
var isOnMethod = interopTypes.HasAttribute(methodDefn, env.ImportAttributeType, false);
var localScript = isOnMethod ? interopTypes.GetValue(ctxt, methodDefn, env.ImportAttributeType, interopTypes.TheScriptProperty, false) : default(JST.Expression);
var prop = methodDefn.DeclaringMember as CCI.Property;
if (prop != null)
{
// XREF1187
if (methodDefn == prop.Getter)
{
// Getter
if (isOnMethod)
{
script = PrefixName
(ctxt,
methodDefn,
GetterSetterAdderRemoverNameFromMethod(ctxt, methodDefn, "get", localScript), false);
return FinalImportScript(ctxt, gensym, rootId, methodDefn, script, false);
}
else if (script != null && script is JST.FunctionExpression)
{
env.Log(new InvalidInteropMessage
(RewriterMsgContext.Method(ctxt, methodDefn),
"property import script cannot be a function"));
throw new DefinitionException();
}
else
{
var function = default(JST.FunctionExpression);
if (gensym != null)
{
var parameters = new Seq<JST.Identifier>();
var body = new Seq<JST.Statement>();
for (var i = 0; i < methodArity; i++)
parameters.Add(gensym());
if (script == null && methodArity == 2 && !methodDefn.IsStatic)
body.Add
(new JST.ReturnStatement
(new JST.IndexExpression
(parameters[0].ToE(), parameters[1].ToE())));
else
{
script = PrefixName
(ctxt, methodDefn, RecasePropertyEvent(ctxt, methodDefn, script), false);
if (methodDefn.IsStatic && methodArity == 0)
body.Add(new JST.ReturnStatement(script));
//.........这里部分代码省略.........
示例14: FinalImportScript
// Take acccount of
// - PassRootAsArgument
// - PassInstanceAsArgument
// - InlineParamsArray
private ImportMethodInfo FinalImportScript(MessageContext ctxt, Func<JST.Identifier> gensym, JST.Identifier rootId, CCI.Method methodDefn, JST.Expression script, bool isNew)
{
if (script == null)
throw new InvalidOperationException("expecting default script value");
var lastArgIsParamsArray = LastArgIsParamsArray(ctxt, methodDefn) && interopTypes.GetValue(ctxt, methodDefn, env.ImportAttributeType, interopTypes.TheInlineParamsArrayProperty);
var methodArity = Arity(methodDefn);
var isInstanceMethod = !(methodDefn.IsStatic || methodDefn is CCI.InstanceInitializer);
var scriptExpectsRoot = interopTypes.GetValue
(ctxt, methodDefn, env.ImportAttributeType, interopTypes.ThePassRootAsArgumentProperty);
var instanceIsThis = isInstanceMethod &&
!interopTypes.GetValue
(ctxt,
methodDefn,
env.ImportAttributeType,
interopTypes.ThePassInstanceAsArgumentProperty);
var expectedScriptArity = methodArity - (lastArgIsParamsArray ? 1 : 0) + (scriptExpectsRoot ? 1 : 0) -
(instanceIsThis ? 1 : 0);
CheckScriptArity(ctxt, methodDefn, script, expectedScriptArity);
var function = default(JST.FunctionExpression);
if (gensym != null)
{
var parameters = new Seq<JST.Identifier>();
var body = new Seq<JST.Statement>();
var callArgs = new Seq<JST.Expression>();
if (lastArgIsParamsArray)
{
var argsId = gensym();
body.Add(JST.Statement.Var(argsId, new JST.ArrayLiteral()));
if (scriptExpectsRoot)
body.Add(JST.Statement.DotCall(argsId.ToE(), Constants.push, rootId.ToE()));
if (!isInstanceMethod)
callArgs.Add(new JST.NullExpression());
for (var i = 0; i < methodArity; i++)
{
var id = gensym();
parameters.Add(id);
if (isInstanceMethod && i == 0)
{
if (instanceIsThis)
callArgs.Add(id.ToE());
else
{
callArgs.Add(new JST.NullExpression());
body.Add(JST.Statement.DotCall(argsId.ToE(), Constants.push, id.ToE()));
}
}
else if (i == methodArity - 1)
{
var iId = gensym();
body.Add
(new JST.IfStatement
(JST.Expression.IsNotNull(id.ToE()),
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(id.ToE(), Constants.length)),
new JST.UnaryExpression(iId.ToE(), JST.UnaryOp.PostIncrement)),
new JST.Statements
(JST.Statement.DotCall
(argsId.ToE(),
Constants.push,
new JST.IndexExpression(id.ToE(), iId.ToE())))))));
}
else
body.Add(JST.Statement.DotCall(argsId.ToE(), Constants.push, id.ToE()));
}
if (script is JST.FunctionExpression)
{
var funcId = gensym();
body.Add(JST.Statement.Var(funcId, script));
script = JST.Expression.Dot(funcId.ToE(), Constants.apply);
}
else
script = JST.Expression.Dot(script, Constants.apply);
callArgs.Add(argsId.ToE());
}
else
{
if (scriptExpectsRoot)
callArgs.Add(rootId.ToE());
for (var i = 0; i < methodArity; i++)
{
var id = gensym();
//.........这里部分代码省略.........
示例15: UsedByMembersClosure
internal void UsedByMembersClosure(Global global, AssemblyDef assemblyDef, TypeDef typeDef, Set<QualifiedMemberName> visitedMemberDefs, Seq<QualifiedMemberName> scc)
{
if (usedByMembers == null)
return;
var self = QualifiedMemberName(global, assemblyDef, typeDef);
if (!visitedMemberDefs.Contains(self))
{
visitedMemberDefs.Add(self);
scc.Add(self);
foreach (var r in usedByMembers)
{
var usedByAssemblyDef = default(AssemblyDef);
var usedByTypeDef = default(TypeDef);
var usedByMemberDef = default(MemberDef);
if (r.PrimTryResolve(global, out usedByAssemblyDef, out usedByTypeDef, out usedByMemberDef))
usedByMemberDef.UsedByMembersClosure
(global, usedByAssemblyDef, usedByTypeDef, visitedMemberDefs, scc);
}
}
}