private static bool IsValid(TemplateArgument a) { if (a.Type.Type == null) { return(true); } var templateParam = a.Type.Type.Desugar() as TemplateParameterType; // HACK: TemplateParameterType.Parameter is null in some corner cases, see the parser return(templateParam == null || templateParam.Parameter != null); }
public TypePrinterResult VisitTemplateArgument(TemplateArgument a) { if (a.Type.Type == null) { return(a.Integral.ToString(CultureInfo.InvariantCulture)); } var type = a.Type.Type.Desugar(); return(type.IsPointerToPrimitiveType() ? IntPtrType : type.IsPrimitiveType(PrimitiveType.Void) ? "object" : type.Visit(this)); }
public override TypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.GetClassTemplateSpecialization() ?? template.Template.TemplatedDecl; TypeMap typeMap; if (!TypeMapDatabase.FindTypeMap(template, out typeMap)) { if (ContextKind == TypePrinterContextKind.Managed && decl == template.Template.TemplatedDecl && template.Arguments.All(IsValid)) { List <TemplateArgument> args = template.Arguments; var @class = (Class)template.Template.TemplatedDecl; TemplateArgument lastArg = args.Last(); return($@"{VisitDeclaration(decl)}<{string.Join(", ", args.Concat(Enumerable.Range(0, @class.TemplateParameters.Count - args.Count).Select( i => lastArg)).Select(this.VisitTemplateArgument))}>"); } if (ContextKind == TypePrinterContextKind.Native) { return(template.Desugared.Visit(this)); } return(decl.Visit(this)); } typeMap.Declaration = decl; typeMap.Type = template; var typePrinterContext = new TypePrinterContext { Type = template, Kind = ContextKind, MarshalKind = MarshalKind }; var type = typeMap.CSharpSignature(typePrinterContext); if (!string.IsNullOrEmpty(type)) { return(new TypePrinterResult { Type = type, TypeMap = typeMap }); } return(decl.Visit(this)); }
public TypePrinterResult VisitTemplateArgument(TemplateArgument a) { if (a.Type.Type == null) { return(a.Integral.ToString(CultureInfo.InvariantCulture)); } var type = a.Type.Type; PrimitiveType pointee; if (type.IsPointerToPrimitiveType(out pointee) && !type.IsConstCharString()) { return($@"CppSharp.Runtime.Pointer<{(pointee == PrimitiveType.Void ? IntPtrType : VisitPrimitiveType(pointee, new TypeQualifiers()).Type)}>"); } return(type.IsPrimitiveType(PrimitiveType.Void) ? "object" : type.Visit(this).Type); }
public override string CSharpSignature(CSharpTypePrinterContext ctx) { if (ctx.CSharpKind == CSharpTypePrinterContextKind.Native) { if (Type.IsAddress()) { return("QList.Internal*"); } return("QList.Internal"); } TemplateSpecializationType templateSpecialization = (TemplateSpecializationType)ctx.Type.Desugar(); TemplateArgument templateArgument = templateSpecialization.Arguments[0]; if (templateArgument.Type.Type.IsPointerToPrimitiveType()) { return("System.Collections.Generic.IList<global::System.IntPtr>"); } return(string.Format("System.Collections.Generic.IList<{0}>", ctx.GetTemplateParameterList())); }
public IEnumerable <IProjectItem> AddProjectItemsForTemplateItem(IProjectItemTemplate templateItem, string fileName, string targetFolder, CreationOptions creationOptions, out List <IProjectItem> itemsToOpen) { IEnumerable <TemplateArgument> templateArguments; IProjectItemTemplate projectItemTemplate = templateItem; string str = fileName; string str1 = targetFolder; IProject project = this.project; if (this.project.TargetFramework == null) { templateArguments = Enumerable.Empty <TemplateArgument>(); } else { TemplateArgument[] templateArgument = new TemplateArgument[] { new TemplateArgument("targetframeworkversion", this.project.TargetFramework.Version.ToString(2)) }; templateArguments = templateArgument; } IEnumerable <TemplateArgument> templateArguments1 = templateArguments; CreationOptions creationOption = creationOptions; IServiceProvider serviceProvider = this.serviceProvider; return(projectItemTemplate.CreateProjectItems(str, str1, project, templateArguments1, creationOption, out itemsToOpen, serviceProvider)); }
public void with_default_constructor_Value_should_be_null() { var argument = new TemplateArgument(); Assert.IsNull(argument.Value); }
public override void CSharpMarshalToNative(MarshalContext ctx) { TextGenerator supportBefore = ctx.SupportBefore; string suffix = ctx.ParameterIndex > 0 ? ctx.ParameterIndex.ToString(CultureInfo.InvariantCulture) : string.Empty; string qList = string.Format("__qList{0}", suffix); supportBefore.WriteLine(string.Format("var {0} = new QtCore.QList.Internal();", qList)); string qListDataData = string.Format("__qlistDataData{0}", suffix); supportBefore.WriteLine("var {0} = (QListData.Data.Internal*) {1}._0.d;", qListDataData, qList); // TODO: tests with Qt shows that while alloc is not smaller than end, it's not equal, it reserves more space actually supportBefore.WriteLine("{0}->alloc = {1}.Count;", qListDataData, ctx.Parameter.Name); supportBefore.WriteLine("{0}->begin = 0;", qListDataData, ctx.Parameter.Name); supportBefore.WriteLine("{0}->end = {1}.Count;", qListDataData, ctx.Parameter.Name); supportBefore.WriteLine("fixed (void** __v = new void*[{0}.Count])", ctx.Parameter.Name); supportBefore.WriteStartBraceIndent(); supportBefore.WriteLine("{0}->array = __v;", qListDataData); supportBefore.WriteCloseBraceIndent(); supportBefore.WriteLine("", qListDataData, ctx.Parameter.Name); var parameterType = ctx.Parameter.Type.Desugar(); TemplateSpecializationType type = parameterType as TemplateSpecializationType; if (type == null) { TypedefType typedef; if (parameterType.IsPointerTo(out typedef)) { type = (TemplateSpecializationType)typedef.Desugar(); } else { parameterType.IsPointerTo(out type); } } Type elementType = type.Arguments[0].Type.Type.Desugar(); string instance = string.Empty; if (!elementType.IsPointerToPrimitiveType()) { instance = string.Format(".{0}", Helpers.InstanceIdentifier); } supportBefore.WriteLine("for (int i = 0; i < {0}.Count; i++)", ctx.Parameter.Name); supportBefore.WriteStartBraceIndent(); Type desugared = ctx.Parameter.Type.Desugar(); TemplateSpecializationType templateSpecializationType = desugared as TemplateSpecializationType; if (templateSpecializationType == null) { Type paramType; desugared.IsPointerTo(out paramType); templateSpecializationType = (TemplateSpecializationType)paramType.Desugar(); } TemplateArgument templateArgument = templateSpecializationType.Arguments[0]; if (templateArgument.Type.ToString() == "string") { supportBefore.WriteLine("{0}->array[i] = Marshal.StringToHGlobalUni({1}[i]).ToPointer();", qListDataData, ctx.Parameter.Name, instance); } else { Class @class; if (templateArgument.Type.Type.TryGetClass(out @class) && @class.IsValueType) { supportBefore.WriteLine("{0}.Internal __value = {1}[i]{2};", @class.Name, ctx.Parameter.Name, instance, Helpers.InstanceIdentifier); supportBefore.WriteLine("{0}->array[i] = &__value;", qListDataData, ctx.Parameter.Name, instance); } else { supportBefore.WriteLine("{0}->array[i] = (void*) {1}[i]{2};", qListDataData, ctx.Parameter.Name, instance); } } supportBefore.WriteCloseBraceIndent(); if (parameterType.IsAddress()) { ctx.Return.Write("new global::System.IntPtr(&{0})", qList); } else { ctx.Return.Write(qList); } }
internal TemplateArgument(TemplateArgument.Internal* native) : this(new global::System.IntPtr(native)) { }
internal TemplateArgument(TemplateArgument.Internal native) : this(&native) { }
private TemplateArgument(TemplateArgument.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
public async void UpdateRequests(List <WikiJobRequest> requests) { using (var client = new WikiClient { ClientUserAgent = "WCLQuickStart/1.0 (your user name or contact information here)" }) { try { // You can create multiple WikiSite instances on the same WikiClient to share the state. var site = _wikiAccessLogic.GetLoggedInWikiSite(_wikiLoginConfig, client, _log); var page = new WikiPage(site, _wikiRequestPage); _log.Information("Pulling requests from job request page for status update."); // Fetch content of job request page so we can update it await page.RefreshAsync(PageQueryOptions.FetchContent | PageQueryOptions.ResolveRedirects); var parser = new WikitextParser(); var wikiText = parser.Parse(page.Content); foreach (WikiJobRequest request in requests) { _log.Information($"Processing request ID: {request.ID} with raw {request.RawRequest}"); //Find corresponding template in the page content var templates = wikiText.Lines.SelectMany(x => x.EnumDescendants().OfType <Template>()); var requestTemplates = templates.Where(template => template.Name.ToPlainText().Equals(_botRequestTemplate)); _log.Information($"{requestTemplates.ToList().Count} templates found for template {_botRequestTemplate}"); _log.Information($"Template id: {requestTemplates.First().Arguments.SingleOrDefault(arg => arg.Name.ToPlainText().Equals("id"))}"); var singletemplate = requestTemplates.First(template => template.EqualsJob(request)); if (singletemplate.Arguments.SingleOrDefault(arg => arg.Name.ToPlainText().Equals("status")) == null) //Status argument doesn't exist in the template { var templateArgument = new TemplateArgument { Name = parser.Parse("status"), Value = parser.Parse(request.Status.ToString()) }; singletemplate.Arguments.Add(templateArgument); } else //Status argument exists { singletemplate.Arguments.Single(arg => arg.Name.ToPlainText().Equals("status")).Value = parser.Parse(request.Status.ToString()); } if (singletemplate.Arguments.SingleOrDefault(arg => arg.Name.ToPlainText().Equals("id")) == null) //ID argument doesn't exist in the template { var templateArgument = new TemplateArgument { Name = parser.Parse("id"), Value = parser.Parse(request.ID.ToString()) }; singletemplate.Arguments.Add(templateArgument); } request.RawRequest = singletemplate.ToString(); _database.UpdateRaw(request.ID, request.RawRequest); //TODO: Make batch operation } //Update the content of the page object and push it live await UpdatePageContent(wikiText.ToString(), "Updating request ids and statuses", page); // We're done here await site.LogoutAsync(); } catch (Exception ex) { _log.Error(ex, "An error occurred while trying to update requests: "); } } }
public static TemplateArgument __CreateInstance(TemplateArgument.Internal native) { return new TemplateArgument(native); }
private TemplateArgument(TemplateArgument.Internal native, bool skipVTables = false) : this(__CopyValue(native), skipVTables) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
private static void* __CopyValue(TemplateArgument.__Internal native) { var ret = Marshal.AllocHGlobal(20); *(TemplateArgument.__Internal*) ret = native; return ret.ToPointer(); }
private bool UnsupportedTemplateArgument(ClassTemplateSpecialization specialization, TemplateArgument a) { if (a.Type.Type == null || CheckIgnoredDeclsPass.IsTypeExternal( specialization.TranslationUnit.Module, a.Type.Type)) { return(true); } var typeIgnoreChecker = new TypeIgnoreChecker(Context.TypeMaps); a.Type.Type.Visit(typeIgnoreChecker); return(typeIgnoreChecker.IsIgnored); }
static bool allPointers(TemplateArgument a) => a.Type.Type?.Desugar().IsAddress() == true;
public static TemplateArgument __CreateInstance(TemplateArgument.Internal native, bool skipVTables = false) { return new TemplateArgument(native, skipVTables); }
private static global::System.IntPtr __CopyValue(TemplateArgument.Internal native) { global::System.IntPtr ret = Marshal.AllocHGlobal(20); *(TemplateArgument.Internal*) ret = native; return ret; }
protected TemplateArgument(TemplateArgument.Internal* native, bool skipVTables = false) { if (native == null) return; __Instance = new global::System.IntPtr(native); }
internal TemplateArgument(TemplateArgument.Internal native) : this(__CopyValue(native)) { }
private static TemplateArgument.Internal* __CopyValue(TemplateArgument.Internal native) { var ret = (TemplateArgument.Internal*) Marshal.AllocHGlobal(40); *ret = native; return ret; }
private TemplateArgument(TemplateArgument.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; }
protected TemplateArgument(TemplateArgument.Internal* native, bool isInternalImpl = false) { __Instance = new global::System.IntPtr(native); }
public IEnumerable <IProjectItem> CreateProjectItems(string name, string targetFolder, IProject project, IEnumerable <TemplateArgument> templateArguments, CreationOptions creationOptions, out List <IProjectItem> itemsToOpen, IServiceProvider serviceProvider) { Uri uri; if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } ICodeDocumentType codeDocumentType = base.GetCodeDocumentType(serviceProvider); if (templateArguments != null) { templateArguments = templateArguments.Concat <TemplateArgument>(TemplateManager.GetDefaultArguments(serviceProvider.ExpressionInformationService())); } else { templateArguments = TemplateManager.GetDefaultArguments(serviceProvider.ExpressionInformationService()); } IEnumerable <IProjectItem> projectItems = Enumerable.Empty <IProjectItem>(); itemsToOpen = new List <IProjectItem>(); using (ProjectPathHelper.TemporaryDirectory temporaryDirectory = new ProjectPathHelper.TemporaryDirectory(true)) { Uri uri1 = new Uri(Microsoft.Expression.Framework.Documents.PathHelper.EnsurePathEndsInDirectorySeparator(temporaryDirectory.Path)); List <DocumentCreationInfo> documentCreationInfos = new List <DocumentCreationInfo>(); List <string> strs = new List <string>(); bool flag = false; foreach (VSTemplateTemplateContentProjectItem templateProjectItem in this.TemplateProjectItems) { if (!templateProjectItem.OpenInEditorSpecified) { continue; } flag = true; break; } bool flag1 = false; string str = CodeGenerator.MakeSafeIdentifier(codeDocumentType, project.DocumentReference.DisplayNameShort, flag1); bool flag2 = true; string str1 = CodeGenerator.MakeSafeIdentifier(codeDocumentType, project.DocumentReference.DisplayNameShort, flag2); TemplateArgument templateArgument = new TemplateArgument("safeprojectname", str); TemplateArgument templateArgument1 = new TemplateArgument("safeprojectname", str1); TemplateArgument templateArgument2 = new TemplateArgument("assemblyname", project.DocumentReference.DisplayNameShort); TemplateArgument templateArgument3 = new TemplateArgument("safeassemblyname", project.DocumentReference.DisplayNameShort.Replace(' ', '\u005F')); foreach (VSTemplateTemplateContentProjectItem vSTemplateTemplateContentProjectItem in this.TemplateProjectItems) { string targetFileName = vSTemplateTemplateContentProjectItem.TargetFileName; if (string.IsNullOrEmpty(targetFileName)) { targetFileName = vSTemplateTemplateContentProjectItem.Value; } TemplateArgument[] templateArgumentArray = new TemplateArgument[] { new TemplateArgument("fileinputname", Path.GetFileNameWithoutExtension(name)), new TemplateArgument("fileinputextension", Path.GetExtension(name)) }; IEnumerable <TemplateArgument> templateArguments1 = templateArgumentArray; targetFileName = TemplateParser.ReplaceTemplateArguments(targetFileName, templateArguments1); templateArguments1 = templateArguments1.Concat <TemplateArgument>(templateArguments); bool flag3 = Path.GetExtension(vSTemplateTemplateContentProjectItem.Value).Equals(codeDocumentType.DefaultFileExtension, StringComparison.OrdinalIgnoreCase); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Microsoft.Expression.Framework.Documents.PathHelper.GetFileOrDirectoryName(targetFileName)); if (serviceProvider.DocumentTypeManager().DocumentTypes[DocumentTypeNamesHelper.Xaml].IsDocumentTypeOf(fileNameWithoutExtension)) { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileNameWithoutExtension); } string str2 = CodeGenerator.MakeSafeIdentifier(codeDocumentType, fileNameWithoutExtension, flag3); IEnumerable <TemplateArgument> templateArguments2 = templateArguments1; TemplateArgument[] templateArgumentArray1 = new TemplateArgument[] { new TemplateArgument("rootnamespace", project.DefaultNamespaceName), new TemplateArgument("projectname", project.DocumentReference.DisplayNameShort), templateArgument2, templateArgument3, null, null, null, null }; templateArgumentArray1[4] = (flag3 ? templateArgument1 : templateArgument); templateArgumentArray1[5] = new TemplateArgument("safeitemname", str2); templateArgumentArray1[6] = new TemplateArgument("safeitemrootname", str2); templateArgumentArray1[7] = new TemplateArgument("culture", (string.IsNullOrEmpty(project.UICulture) ? CultureInfo.CurrentUICulture.ToString() : project.UICulture)); templateArguments1 = templateArguments2.Concat <TemplateArgument>(templateArgumentArray1); try { uri = base.ResolveFileUri(targetFileName, uri1); } catch (UriFormatException uriFormatException) { continue; } IDocumentType documentType = project.GetDocumentType(targetFileName); foreach (IDocumentType documentType1 in serviceProvider.DocumentTypeManager().DocumentTypes) { if (vSTemplateTemplateContentProjectItem.SubType != documentType1.Name) { continue; } documentType = documentType1; } if (!base.CreateFile(vSTemplateTemplateContentProjectItem.Value, base.TemplateLocation, uri, vSTemplateTemplateContentProjectItem.ReplaceParameters, templateArguments1)) { continue; } string str3 = ProjectItemTemplate.AdjustTargetFolder(targetFolder, uri1.LocalPath, uri.LocalPath); DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo() { SourcePath = uri.LocalPath, TargetFolder = str3, DocumentType = documentType, CreationOptions = creationOptions }; documentCreationInfos.Add(documentCreationInfo); if (!flag) { if (strs.Count > 0) { continue; } strs.Add(Path.Combine(str3, Path.GetFileName(uri.LocalPath))); } else { if (!vSTemplateTemplateContentProjectItem.OpenInEditor) { continue; } strs.Add(Path.Combine(str3, Path.GetFileName(uri.LocalPath))); } } if (documentCreationInfos.Count > 0) { projectItems = project.AddItems(documentCreationInfos); } if (projectItems.Any <IProjectItem>()) { for (int i = 0; i < strs.Count; i++) { IProjectItem projectItem = projectItems.FirstOrDefault <IProjectItem>((IProjectItem item) => item.DocumentReference.Path.Equals(strs[i], StringComparison.OrdinalIgnoreCase)); if (projectItem != null) { itemsToOpen.Add(projectItem); } } projectItems = projectItems.Concat <IProjectItem>(this.AddAssemblies(project)); } } if (base.BuildOnLoad) { IProjectManager projectManager = serviceProvider.ProjectManager(); IProjectBuildContext activeBuildTarget = projectManager.ActiveBuildTarget; projectManager.BuildManager.Build(activeBuildTarget, null, true); KnownProjectBase knownProjectBase = project as KnownProjectBase; if (knownProjectBase != null) { knownProjectBase.CheckForChangedOrDeletedItems(); } } return(projectItems); }