Exemple #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));
 }
Exemple #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)));
 }
Exemple #4
0
 int IMethodMemberDictionary.IndexOf(IMethodMember method)
 {
     if (method is TMethod)
     {
         return(this.IndexOf((TMethod)method));
     }
     return(-1);
 }
Exemple #5
0
 public void RegisterGenericMethod(IMethodMember targetSignature, IControlledTypeCollection typeParameters)
 {
     if (!this.IsGenericDefinition)
     {
         throw new InvalidOperationException();
     }
     this.CheckGenericCache();
     this.genericCache.RegisterGenericMethod(targetSignature, typeParameters);
 }
Exemple #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]));
        }
Exemple #7
0
 public void ReferenceDeclaration(IMethodMember declaration)
 {
     if (declaration is IIntermediateMethodMember)
     {
         this.ReferenceDeclaration((IIntermediateMethodMember)declaration);
     }
     else
     {
         this.Formatter.ReferenceDeclaration(declaration);
     }
 }
Exemple #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);
         }
     }
 }
Exemple #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;
     }
 }
Exemple #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);
            }
        }
Exemple #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);
         }
     }
 }
Exemple #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);
         }
     }
 }
Exemple #13
0
 protected abstract IPropertyMethodMember OnGetMethod(IMethodMember originalMethod);
Exemple #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);
        }
Exemple #15
0
 public abstract string GetEntryPointCommand(IMethodMember entrypointMethod, IIntermediateCompilerOptions options);
Exemple #16
0
 public virtual void TranslateMember(IMethodMember methodMember)
 {
     this.TranslateMember <IMethodParameterMember, IMethodTypeParameterMember, CodeMemberMethod, IMemberParentType>(methodMember);
 }
Exemple #17
0
 protected override IPropertyMethodMember OnGetMethod(IMethodMember originalMethod)
 {
     return(new _MethodMember(this.Parent, (IStructMethodMember)originalMethod));
 }
Exemple #18
0
 public MethodTypeParameterMember(string name, IMethodMember parentTarget)
     : base(name, parentTarget)
 {
 }
Exemple #19
0
 public void RegisterGenericChild(IMethodParent parent, IMethodMember genericChild)
 {
     throw new NotSupportedException();
 }
Exemple #20
0
 public void ReferenceDeclaration(IMethodMember declaration)
 {
     referenceStack.Push(declaration);
 }
Exemple #21
0
 public void RegisterGenericChild(IMethodParent parent, IMethodMember genericChild)
 {
     this.CheckGenericCache();
     this.genericCache.RegisterGenericChild(parent, genericChild);
 }
Exemple #22
0
 protected abstract IMethodMember OnGetMethod(IMethodMember original);
Exemple #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)
 {
 }
Exemple #24
0
 public void RegisterGenericMethod(IMethodMember targetSignature, IControlledTypeCollection typeParameters)
 {
     this.CheckGenericCache();
     this.genericCache.RegisterGenericMethod(targetSignature, typeParameters);
 }
Exemple #25
0
 public void ReferenceDeclaration(IMethodMember declaration)
 {
 }
Exemple #26
0
 public MethodParameterMembers(IMethodMember targetDeclaration)
     : base(targetDeclaration)
 {
 }
Exemple #27
0
 protected override IMethodMember OnGetMethod(IMethodMember original)
 {
     return(new _MethodMember((IClassMethodMember)original, this.Parent));
 }
Exemple #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();
            }
        }