本文整理汇总了C#中System.Compiler.Module类的典型用法代码示例。如果您正苦于以下问题:C# Module类的具体用法?C# Module怎么用?C# Module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Module类属于System.Compiler命名空间,在下文中一共展示了Module类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveReference
public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module module) {
if (reference == null) throw new ArgumentNullException("reference");
//Console.WriteLine("resolving {0}", reference.StrongName);
// try to get it from the cache
string name = reference.StrongName;
if (cache.ContainsKey(name)) return (cache[name]);
// try to get it from the gac
if (useGac) {
string location = GlobalAssemblyCache.GetLocation(reference);
if (location != null) {
AssemblyNode assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false);
if (assembly != null) {
Add(assembly);
return (assembly);
}
}
}
// couldn't find it; return null
// Console.WriteLine("returning null on request for {0}", reference.StrongName);
//OnUnresolvedAssemblyReference(reference, module);
return (null);
}
示例2: Parse
//IDebugExpressionEvaluator
public HRESULT Parse(
[In,MarshalAs(UnmanagedType.LPWStr)]
string pszExpression,
PARSEFLAGS flags,
uint radix,
out string pbstrErrorMessages,
out uint perrorCount,
out IDebugParsedExpression ppparsedExpression
)
{
HRESULT hr = (HRESULT)HResult.S_OK;
perrorCount = 0;
pbstrErrorMessages = null;
ppparsedExpression = null;
ErrorNodeList errors = new ErrorNodeList();
Module symbolTable = new Module();
Document doc = this.cciEvaluator.ExprCompiler.CreateDocument(null, 1, pszExpression);
IParser exprParser = this.cciEvaluator.ExprCompiler.CreateParser(doc.Name, doc.LineNumber, doc.Text, symbolTable, errors, null);
Expression parsedExpression = exprParser.ParseExpression();
perrorCount = (uint)errors.Count;
if (perrorCount > 0)
pbstrErrorMessages = errors[0].GetMessage();
else
ppparsedExpression = new BaseParsedExpression(pszExpression, parsedExpression, this);
return hr;
}
示例3: CollectOldExpressions
public CollectOldExpressions(Module module, Method method, ContractNodes contractNodes, Dictionary<TypeNode, Local> closureLocals,
int localCounterStart, Class initialClosureClass)
: this(module, method, contractNodes, closureLocals, localCounterStart)
{
this.topLevelClosureClass = initialClosureClass;
this.currentClosureClass = initialClosureClass;
}
示例4: Specializer
public Specializer(Module targetModule, TypeNodeList pars, TypeNodeList args)
{
Debug.Assert(pars != null && pars.Count > 0);
Debug.Assert(args != null && args.Count > 0);
this.pars = pars;
this.args = args;
this.TargetModule = targetModule;
}
示例5: Duplicator
/// <param name="module">The module into which the duplicate IR will be grafted.</param>
/// <param name="type">The type into which the duplicate Member will be grafted. Ignored if entire type, or larger unit is duplicated.</param>
public Duplicator(Module/*!*/ module, TypeNode type)
{
this.TargetModule = module;
this.TargetType = this.OriginalTargetType = type;
this.DuplicateFor = new TrivialHashtable();
this.TypesToBeDuplicated = new TrivialHashtable();
//^ base();
}
示例6: DuplicatorForContractsAndClosures
public DuplicatorForContractsAndClosures(Module module, Method sourceMethod, Method targetMethod,
ContractNodes contractNodes, bool mapParameters)
: base(module, targetMethod.DeclaringType)
{
this.sourceMethod = sourceMethod;
this.targetMethod = targetMethod;
this.RemoveNameForLocals = true;
Duplicator dup = this;
if (mapParameters)
{
if (sourceMethod.ThisParameter != null)
{
if (targetMethod.ThisParameter != null)
{
dup.DuplicateFor[sourceMethod.ThisParameter.UniqueKey] = targetMethod.ThisParameter;
}
else
{
// target is a static wrapper. But duplicator cannot handle This -> Parameter conversion
// so we handle it explicitly here in this visitor.
replaceThisWithParameter = targetMethod.Parameters[0];
}
}
if (sourceMethod.Parameters != null && targetMethod.Parameters != null
&& sourceMethod.Parameters.Count == targetMethod.Parameters.Count)
{
for (int i = 0, n = sourceMethod.Parameters.Count; i < n; i++)
{
dup.DuplicateFor[sourceMethod.Parameters[i].UniqueKey] = targetMethod.Parameters[i];
}
}
}
var originalType = HelperMethods.IsContractTypeForSomeOtherType(sourceMethod.DeclaringType, contractNodes);
if (originalType != null)
{
var contractType = this.contractClass = sourceMethod.DeclaringType;
while (contractType.Template != null)
{
contractType = contractType.Template;
}
while (originalType.Template != null)
{
originalType = originalType.Template;
}
// forward ContractType<A,B> -> originalType<A',B'>
this.contractClassToForward = contractType;
this.targetTypeToForwardTo = originalType;
//dup.DuplicateFor[contractType.UniqueKey] = originalType;
}
}
示例7: Write
public static void Write(Compilation compilation, Module module, CompilerParameters options) {
XmlTextWriter writer = new XmlTextWriter(module.Name + ".source.xml", Encoding.Default);
SourceContextWriter scw = new SourceContextWriter(writer);
writer.WriteStartDocument();
writer.WriteStartElement("Module");
writer.WriteAttributeString("name", module.Name);
scw.VisitCompilation(compilation);
writer.WriteEndElement(); // Module
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
示例8: ReplaceResult
readonly private TypeNode declaringType; // needed to copy anonymous delegates into
public ReplaceResult(Method containingMethod, Local r, Module assemblyBeingRewritten) {
Contract.Requires(containingMethod != null);
this.assemblyBeingRewritten = assemblyBeingRewritten;
this.declaringType = containingMethod.DeclaringType;
this.topLevelMethodFormals = containingMethod.TemplateParameters;
this.originalLocalForResult = r;
this.delegateNestingLevel = 0;
}
示例9: AssemblyReferenceResolution
/// <summary>
/// Resolves assembly references based on the library paths specified.
/// Tries to resolve to ".dll" or ".exe". First found wins.
/// </summary>
/// <param name="assemblyReference">Reference to resolve.</param>
/// <param name="referencingModule">Referencing module.</param>
/// <returns>The resolved assembly node (null if not found).</returns>
private static AssemblyNode AssemblyReferenceResolution (AssemblyReference assemblyReference, Module referencingModule) {
AssemblyNode a = ProbeForAssembly(assemblyReference.Name, referencingModule.Directory, DllAndExeExt);
return a;
}
示例10: DuplicatorForContractsAndClosures
public DuplicatorForContractsAndClosures(Module module, Method sourceMethod, Method targetMethod,
ContractNodes contractNodes, bool mapParameters)
: base(module, targetMethod.DeclaringType)
{
this.sourceMethod = sourceMethod;
this.targetMethod = targetMethod;
this.RemoveNameForLocals = true;
Duplicator dup = this;
if (mapParameters)
{
if (sourceMethod.ThisParameter != null)
{
if (targetMethod.ThisParameter != null)
{
dup.DuplicateFor[sourceMethod.ThisParameter.UniqueKey] = targetMethod.ThisParameter;
}
else
{
// target is a static wrapper. But duplicator cannot handle This -> Parameter conversion
// so we handle it explicitly here in this visitor.
replaceThisWithParameter = targetMethod.Parameters[0];
}
}
if (sourceMethod.Parameters != null && targetMethod.Parameters != null
&& sourceMethod.Parameters.Count == targetMethod.Parameters.Count)
{
for (int i = 0, n = sourceMethod.Parameters.Count; i < n; i++)
{
dup.DuplicateFor[sourceMethod.Parameters[i].UniqueKey] = targetMethod.Parameters[i];
}
}
// This code makes sure that generic method parameters used by contracts inherited from contract class
// are correctly replaced by the one defined in the target method.
// Without this mapping <c>CheckPost</c> method in generated async closure class would contain an invalid
// reference to a generic contract method parameter instead of generic async closure type parameter.
// For more about this problem see comments for Microsoft.Contracts.Foxtrot.EmitAsyncClosure.GenericTypeMapper class
// and issue #380.
if (sourceMethod.TemplateParameters != null && targetMethod.TemplateParameters != null
&& sourceMethod.TemplateParameters.Count == targetMethod.TemplateParameters.Count)
{
for (int i = 0, n = sourceMethod.TemplateParameters.Count; i < n; i++)
{
dup.DuplicateFor[sourceMethod.TemplateParameters[i].UniqueKey] = targetMethod.TemplateParameters[i];
}
}
}
var originalType = HelperMethods.IsContractTypeForSomeOtherType(sourceMethod.DeclaringType, contractNodes);
if (originalType != null)
{
var contractType = this.contractClass = sourceMethod.DeclaringType;
while (contractType.Template != null)
{
contractType = contractType.Template;
}
while (originalType.Template != null)
{
originalType = originalType.Template;
}
// forward ContractType<A,B> -> originalType<A',B'>
this.contractClassToForward = contractType;
this.targetTypeToForwardTo = originalType;
//dup.DuplicateFor[contractType.UniqueKey] = originalType;
}
}
示例11: ProvideNestedTypes
private void ProvideNestedTypes(TypeNode/*!*/ dup, object/*!*/ handle)
{
TypeNode template = (TypeNode)handle;
TypeNode savedTargetType = this.TargetType;
Module savedTargetModule = this.TargetModule;
this.TargetType = dup;
//^ assume dup.DeclaringModule != null;
this.TargetModule = dup.DeclaringModule;
this.FindTypesToBeDuplicated(template.NestedTypes);
dup.NestedTypes = this.VisitNestedTypes(dup, template.NestedTypes);
this.TargetModule = savedTargetModule;
this.TargetType = savedTargetType;
}
示例12: Duplicator
/// <param name="module">The module into which the duplicate IR will be grafted.</param>
/// <param name="type">The type into which the duplicate Member will be grafted. Ignored if entire type, or larger unit is duplicated.</param>
public Duplicator(Module module, TypeNode type)
: base(module, type)
{
}
示例13: MyMethodBodySpecializer
public MyMethodBodySpecializer(Module module, TypeNodeList source, TypeNodeList target)
: base(module, source, target)
{
}
示例14: ResolveReference
/// <summary>
/// This is used to try and resolve an assembly reference
/// </summary>
/// <param name="reference">The assembly reference</param>
/// <param name="referrer">The module requiring the reference</param>
/// <returns>The assembly node if resolved or null if not resolved</returns>
public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module referrer)
{
AssemblyNode assembly;
if(reference == null)
throw new ArgumentNullException("reference");
// Try to get it from the cache
string name = reference.StrongName;
if(cache.ContainsKey(name))
return cache[name];
// Try to get it from the GAC if so indicated
if(this.UseGac)
{
string location = GlobalAssemblyCache.GetLocation(reference);
if(location != null)
{
assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false);
if(assembly != null)
{
this.Add(assembly);
return assembly;
}
}
}
// Try the redirects if not found
foreach(BindingRedirectSettings brs in redirects)
if(brs.IsRedirectFor(name) && cache.ContainsKey(brs.StrongName))
{
ConsoleApplication.WriteMessage(LogLevel.Info, "Using redirect '{0}' in place of '{1}'",
brs.StrongName, name);
assembly = cache[brs.StrongName];
// Add the same assembly under the current name
cache.Add(name, assembly);
return assembly;
}
// Couldn't find it; return null
return null;
}
示例15: UnresolvedReference
/// <summary>
/// This is called if assembly reference resolution fails after probing
/// </summary>
/// <param name="reference">The assembly reference</param>
/// <param name="module">The module</param>
/// <returns>Always returns null</returns>
private AssemblyNode UnresolvedReference(AssemblyReference reference, Module module)
{
// Don't raise the event if ignored
if(!ignoreIfUnresolved.Contains(reference.Name))
OnUnresolvedAssemblyReference(reference, module);
else
ConsoleApplication.WriteMessage(LogLevel.Warn, "Ignoring unresolved assembly " +
"reference: {0} ({1}) required by {2}", reference.Name, reference.StrongName,
module.Name);
return null;
}