Ejemplo n.º 1
0
        private bool ValidateEntryPoint(IMethodMember value)
        {
            if (((IDeclaredType)value.ParentTarget).IsGeneric)
            {
                return(false);
            }
            if (value.Name != "Main")
            {
                return(false);
            }
            if (value.Parameters.Count < 0 || value.Parameters.Count > 1)
            {
                return(false);
            }
            if (value.Parameters.Count == 0)
            {
                return(value.ReturnType.Equals(typeof(int).GetTypeReference()) || value.ReturnType.Equals(typeof(void).GetTypeReference()));
            }
            IMethodParameterMember impm = value.Parameters[value.Parameters.Keys[0]];

            if (impm.ParameterType.ArrayElementType == null || impm.ParameterType.ArrayRank == 0)
            {
                return((impm.ParameterType.Equals(typeof(string).GetTypeReference())) && (value.ReturnType.Equals(typeof(int).GetTypeReference()) || value.ReturnType.Equals(typeof(void).GetTypeReference())));
            }
            else if (impm.ParameterType.ArrayRank == 1 && impm.ParameterType.ArrayElementType != null)
            {
                return(((impm.ParameterType.ArrayElementType.ArrayRank == 0 || impm.ParameterType.ArrayElementType.ArrayElementType == null) && impm.ParameterType.ArrayElementType.Equals(typeof(string).GetTypeReference())) && (value.ReturnType.Equals(typeof(int).GetTypeReference()) || value.ReturnType.Equals(typeof(void).GetTypeReference())));
            }
            return(false);
        }
 int IMethodMemberDictionary.IndexOf(IMethodMember method)
 {
     if (!(method is TIntermediateMethod))
     {
         throw new ArgumentException("method");
     }
     return(this.IndexOf((TIntermediateMethod)method));
 }
Ejemplo n.º 3
0
 public override string GetEntryPointCommand(IMethodMember entrypointMethod, IIntermediateCompilerOptions options)
 {
     if (entrypointMethod == null)
     {
         throw new ArgumentNullException("entrypointMethod");
     }
     return(string.Format(EntryPointCommand, ((IDeclaredType)entrypointMethod.ParentTarget).GetTypeName(CodeGeneratorHelper.DefaultTranslatorOptions)));
 }
Ejemplo n.º 4
0
 int IMethodMemberDictionary.IndexOf(IMethodMember method)
 {
     if (method is TMethod)
     {
         return(this.IndexOf((TMethod)method));
     }
     return(-1);
 }
Ejemplo n.º 5
0
 public void RegisterGenericMethod(IMethodMember targetSignature, IControlledTypeCollection typeParameters)
 {
     if (!this.IsGenericDefinition)
     {
         throw new InvalidOperationException();
     }
     this.CheckGenericCache();
     this.genericCache.RegisterGenericMethod(targetSignature, typeParameters);
 }
Ejemplo n.º 6
0
        public int IndexOf(IMethodMember method)
        {
            int valueIndex = this.master.Values.IndexOf(new MasterDictionaryEntry <IMember>(this, method));

            if (valueIndex == -1)
            {
                return(-1);
            }
            return(this.identifiers.GetIndexOf(master.Keys[valueIndex]));
        }
Ejemplo n.º 7
0
 public void ReferenceDeclaration(IMethodMember declaration)
 {
     if (declaration is IIntermediateMethodMember)
     {
         this.ReferenceDeclaration((IIntermediateMethodMember)declaration);
     }
     else
     {
         this.Formatter.ReferenceDeclaration(declaration);
     }
 }
Ejemplo n.º 8
0
 private static void AddImplementations(HashSet <IInterfaceType> results, IMethodMember aM)
 {
     if (aM != null && aM is IExtendedInstanceMember)
     {
         var ieimAM = (IExtendedInstanceMember)aM;
         foreach (var t in ieimAM.Implementations)
         {
             results.Add(t);
         }
     }
 }
Ejemplo n.º 9
0
 void _onRaiseMethod_Disposed(object sender, EventArgs e)
 {
     if (this._onRaiseMethod != null)
     {
         _onRaiseMethod.Disposed -= new EventHandler(_onRaiseMethod_Disposed);
         this._onRaiseMethod      = null;
     }
     if (this.onRaiseMethod != null)
     {
         this.onRaiseMethod.Dispose();
         this.onRaiseMethod = null;
     }
 }
Ejemplo n.º 10
0
        private ITypeParent OnGetParentImpl()
        {
            ITypeParent declParent = this.Original.Parent;

            if (declParent == null)
            {
                return(null);
            }
            else
            {
                if (this.Original.IsGenericConstruct)
                {
                    if (declParent is IGenericType)
                    {
                        IGenericType genericParent = ((IGenericType)(declParent));
                        if (genericParent.IsGenericConstruct)
                        {
                            if (!genericParent.IsGenericDefinition)
                            {
                                genericParent = (IGenericType)genericParent.ElementType;
                            }
                            return((ITypeParent)genericParent.MakeGenericClosure(this.GenericParameters.Take(genericParent.GenericParameters.Count).ToCollection()));
                        }
                        else
                        {
                            return((ITypeParent)genericParent);
                        }
                    }
                    else if (declParent is IMethodMember)
                    {
                        IMethodMember genericParent = ((IMethodMember)(declParent));
                        if (genericParent.IsGenericConstruct)
                        {
                            if (!genericParent.IsGenericDefinition)
                            {
                                genericParent = (IMethodMember)genericParent.GetGenericDefinition();
                            }
                            return((ITypeParent)genericParent.MakeGenericClosure(this.GenericParameters.Take(genericParent.GenericParameters.Count).ToCollection()));
                        }
                    }
                }
                return(declParent);
            }
        }
Ejemplo n.º 11
0
 public void RegisterGenericMethod(IMethodMember targetMethod, IControlledTypeCollection typeParameters)
 {
     lock (this.syncObject)
     {
         if (this.disposing)
         {
             return;
         }
         if (this.genericCache == null)
         {
             this.genericCache = new ControlledDictionary <IControlledTypeCollection, TMethod>();
         }
         TMethod dummy = default(TMethod);
         if (!this.ContainsGenericMethod(typeParameters, ref dummy))
         {
             this.genericCache._Add(typeParameters, (TMethod)targetMethod);
         }
     }
 }
Ejemplo n.º 12
0
 public void RegisterGenericChild(IMethodParent parent, IMethodMember genericChild)
 {
     lock (syncObject)
     {
         if (this.disposing)
         {
             return;
         }
         if (!(genericChild is TMethod))
         {
             throw new ArgumentException(ThrowHelper.GetExceptionMessage(ExceptionMessageId.ValueIsWrongType, "genericChild", genericChild.GetType().FullName, typeof(TMethod).FullName), "genericChild");
         }
         if (this.genericChildCache == null)
         {
             this.genericChildCache = new Dictionary <IMethodParent, TMethod>();
         }
         if (!genericChildCache.ContainsKey(parent))
         {
             genericChildCache.Add(parent, (TMethod)genericChild);
         }
     }
 }
Ejemplo n.º 13
0
 protected abstract IPropertyMethodMember OnGetMethod(IMethodMember originalMethod);
Ejemplo n.º 14
0
        public static IMethodParameterMember <TMethod, TMethodParent> ParamOf <TMethod, TMethodParent>(this string name, IMethodMember <TMethod, TMethodParent> method)
            where TMethod :
        IMethodMember <TMethod, TMethodParent>
            where TMethodParent :
        IMethodParent <TMethod, TMethodParent>
        {
            IMethodParameterMember <TMethod, TMethodParent> result;

            method.Parameters.TryGetValue(TypeSystemIdentifiers.GetMemberIdentifier(name), out result);
            return(result);
        }
Ejemplo n.º 15
0
 public abstract string GetEntryPointCommand(IMethodMember entrypointMethod, IIntermediateCompilerOptions options);
Ejemplo n.º 16
0
 public virtual void TranslateMember(IMethodMember methodMember)
 {
     this.TranslateMember <IMethodParameterMember, IMethodTypeParameterMember, CodeMemberMethod, IMemberParentType>(methodMember);
 }
Ejemplo n.º 17
0
 protected override IPropertyMethodMember OnGetMethod(IMethodMember originalMethod)
 {
     return(new _MethodMember(this.Parent, (IStructMethodMember)originalMethod));
 }
Ejemplo n.º 18
0
 public MethodTypeParameterMember(string name, IMethodMember parentTarget)
     : base(name, parentTarget)
 {
 }
Ejemplo n.º 19
0
 public void RegisterGenericChild(IMethodParent parent, IMethodMember genericChild)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 20
0
 public void ReferenceDeclaration(IMethodMember declaration)
 {
     referenceStack.Push(declaration);
 }
Ejemplo n.º 21
0
 public void RegisterGenericChild(IMethodParent parent, IMethodMember genericChild)
 {
     this.CheckGenericCache();
     this.genericCache.RegisterGenericChild(parent, genericChild);
 }
Ejemplo n.º 22
0
 protected abstract IMethodMember OnGetMethod(IMethodMember original);
Ejemplo n.º 23
0
 /// <summary>
 /// Creates a new instance of <see cref="MethodParameterMember"/>
 /// with the parameter type, name and target provided.
 /// </summary>
 /// <param name="nameAndType">The type and name of the parameter.</param>
 /// <param name="parentTarget">The place the parameter exists on.</param>
 public MethodParameterMember(TypedName nameAndType, IMethodMember parentTarget)
     : base(nameAndType, parentTarget)
 {
 }
Ejemplo n.º 24
0
 public void RegisterGenericMethod(IMethodMember targetSignature, IControlledTypeCollection typeParameters)
 {
     this.CheckGenericCache();
     this.genericCache.RegisterGenericMethod(targetSignature, typeParameters);
 }
Ejemplo n.º 25
0
 public void ReferenceDeclaration(IMethodMember declaration)
 {
 }
Ejemplo n.º 26
0
 public MethodParameterMembers(IMethodMember targetDeclaration)
     : base(targetDeclaration)
 {
 }
Ejemplo n.º 27
0
 protected override IMethodMember OnGetMethod(IMethodMember original)
 {
     return(new _MethodMember((IClassMethodMember)original, this.Parent));
 }
Ejemplo n.º 28
0
        private void CompileToResponse(TemporaryDirectory td, TempFileCollection tfc, List <string> files, Stack <IIntermediateProject> partialCompletions, Dictionary <IIntermediateModule, List <string> > moduleFiles, out IIntermediateCompilerCommandLineModule module, out List <string> commandSequences, out string response)
        {
            module           = (IIntermediateCompilerCommandLineModule)this.Module;
            commandSequences = new List <string>();
            if (this.Project.OutputType == ProjectOutputType.ConsoleApplication || this.Project.OutputType == ProjectOutputType.WindowsApplication)
            {
                IMethodMember entryPoint = Project.EntryPoint;
                if (entryPoint != null && ((IDeclaredType)entryPoint.ParentTarget).Module != Project.RootModule)
                {
                    IClassType entryPointCover = Project.Partials.AddNew().DefaultNameSpace.Classes.AddNew(Project.Classes.GetUniqueName("_cover"));

                    entryPointCover.Attributes.AddNew(typeof(CompilerGeneratedAttribute));
                    entryPointCover.IsStatic    = true;
                    entryPointCover.AccessLevel = DeclarationAccessLevel.Internal;
                    entryPointCover.Module      = Project.RootModule;
                    IMethodMember coverPoint = entryPointCover.Methods.AddNew(new TypedName(entryPoint.Name, entryPoint.ReturnType));
                    coverPoint.Attributes.AddNew(typeof(CompilerGeneratedAttribute));
                    foreach (IMethodParameterMember impm in entryPoint.Parameters.Values)
                    {
                        coverPoint.Parameters.AddNew(new TypedName(impm.Name, impm.ParameterType));
                    }

                    coverPoint.Summary = "Entrypoint cover method, invokes the true entrypoint in a different module.";
                    IMethodInvokeExpression imie = entryPoint.GetReference().Invoke();
                    foreach (IMethodParameterMember impm in entryPoint.Parameters.Values)
                    {
                        imie.ArgumentExpressions.Add(impm.GetReference());
                    }
                    if (!(coverPoint.ReturnType.Equals(typeof(void).GetTypeReference())))
                    {
                        coverPoint.Return(imie);
                    }
                    else
                    {
                        coverPoint.CallMethod(imie);
                    }
                    string entryFile = ProjectTranslator.WriteFile(this.Project, this.Translator, td, tfc, partialCompletions, entryPointCover, ".cs", "    ");
                    moduleFiles[Project.RootModule].Add(entryFile);
                    files.Add(entryFile);
                    commandSequences.Add(module.GetEntryPointCommand(coverPoint, this.Options));
                    this.Project.Partials.Remove((IIntermediateProject)entryPointCover.ParentTarget.ParentTarget);
                }
                else
                {
                    commandSequences.Add(module.GetEntryPointCommand(entryPoint, this.Options));
                }
            }
            List <string> moduleCommandLines = new List <string>();

            foreach (IIntermediateModule iim in this.Project.Modules.Values)
            {
                string[] moduleFileNames = new string[moduleFiles[iim].Count + (iim == this.Project.RootModule ? this.Options.ExtraFiles.Count() : 0)];
                for (int i = 0; i < moduleFiles[iim].Count; i++)
                {
                    moduleFileNames[i] = moduleFiles[iim][i];
                }
                if (iim == this.Project.RootModule)
                {
                    int exC   = this.Options.ExtraFiles.Count();
                    int exO   = moduleFiles[iim].Count;
                    int index = exO;
                    foreach (var extraFile in this.Options.ExtraFiles)
                    {
                        var tempFile = td.Directories.GetTemporaryDirectory(iim.Name).Files.GetTemporaryFile(Path.GetFileName(extraFile));
                        tempFile.CloseStream();
                        File.Copy(extraFile, tempFile.FileName, true);
                        moduleFileNames[index++] = tempFile.FileName;
                    }
                }
                moduleCommandLines.AddRange(module.GetModuleCommand(iim, moduleFileNames, null, this.Options));
            }
            bool allowPartials = this.Translator.Options.AllowPartials;

            this.Translator.Options.AllowPartials = false;
            ProjectDependencyReport pdr = new ProjectDependencyReport(this.Project, this.Translator.Options);

            pdr.Begin();
            this.Translator.Options.AllowPartials = allowPartials;
            if (module.Supports(CompilerModuleSupportFlags.Optimization))
            {
                commandSequences.Add(module.GetOptimizationCommand(this.Options.Optimize, this.Options));
            }
            if (module.Supports(CompilerModuleSupportFlags.DebuggerSupport))
            {
                commandSequences.Add(module.GetDebugCommand(this.Options.DebugSupport, this.Options));
            }
            if (module.Supports(CompilerModuleSupportFlags.XMLDocumentation))
            {
                commandSequences.Add(module.GetXMLDocumentationCommand(this.Options.GenerateXMLDocs, this.Options));
            }
            commandSequences.AddRange(module.GetReferencesCommand(Tweaks.TranslateArray(pdr.CompiledAssemblyReferences.ToArray(), a =>
            {
                return(a.Location);
            }), this.Options));
            if (module.Supports(CompilerModuleSupportFlags.MultiFileAssemblies))
            {
                commandSequences.AddRange(moduleCommandLines.ToArray());
            }
            else
            {
                commandSequences.Add(module.GetOutputCommand(this.Options.Target, this.Options));
                commandSequences.AddRange(module.GetSourcesCommand(files.ToArray(), this.Options));
            }
            response = null;
            if (module.Supports(CompilerModuleSupportFlags.ResponseFile))
            {
                response = tfc.AddExtension("response");
                StreamWriter responseWriter = new StreamWriter(new FileStream(response, FileMode.Create));
                //string[] lines = fullCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in commandSequences)
                {
                    responseWriter.WriteLine(s);
                }
                responseWriter.Flush();
                responseWriter.Close();
            }
        }