public Tuple <IIntermediateClassType, IIntermediateInterfaceType> Build(Tuple <ParserCompiler, RuleSymbolBuilder, IIntermediateAssembly> input) { this.compiler = input.Item1; this.commonSymbol = input.Item2; this.assembly = input.Item3; INamespaceDeclaration targetSpace; var targetSpaceName = TypeSystemIdentifiers.GetDeclarationIdentifier(string.Format("{0}.Cst", this.assembly.DefaultNamespace.FullName)); if (!assembly.Namespaces.PathExists(targetSpaceName.Name)) { targetSpace = this.assembly.DefaultNamespace.Namespaces.Add("Cst"); } else { targetSpace = this.assembly.DefaultNamespace.Namespaces[targetSpaceName]; } var mutableTargetSpace = (IIntermediateNamespaceDeclaration)targetSpace; this.resultInterface = mutableTargetSpace.Parts.Add().Interfaces.Add("I{0}Rule", compiler.Source.Options.AssemblyName); this.resultClass = mutableTargetSpace.Parts.Add().Classes.Add("{0}RuleBase", compiler.Source.Options.AssemblyName); this.resultClass.AccessLevel = AccessLevelModifiers.Internal; this.resultClass.ImplementedInterfaces.ImplementInterfaceQuick(resultInterface); this.resultInterface.AccessLevel = AccessLevelModifiers.Public; this.interfaceContext = this.BuildContext(); this.interfaceParent = this.BuildParent(); this.classContextField = this.BuildClassContextField(); this.classParentField = this.BuildClassParentField(); this.classContext = BuildClassContext(); this.classParent = BuildClassParent(); this.resultClass.SpecialModifier = SpecialClassModifier.Abstract; return(Tuple.Create(resultClass, resultInterface)); }
public IIntermediateInterfaceType Build(Tuple <ParserCompiler, CommonSymbolBuilder, IIntermediateAssembly> input) { this.compiler = input.Item1; this.rootSymbol = input.Item2; this.assembly = input.Item3; this._identityManager = (IIntermediateCliManager)this.assembly.IdentityManager; INamespaceDeclaration targetSpace; var targetSpaceName = TypeSystemIdentifiers.GetDeclarationIdentifier(string.Format("{0}.Cst", this.assembly.DefaultNamespace.FullName)); if (!assembly.Namespaces.PathExists(targetSpaceName.Name)) { targetSpace = this.assembly.DefaultNamespace.Namespaces.Add("Cst"); } else { targetSpace = this.assembly.DefaultNamespace.Namespaces[targetSpaceName]; } var mutableTargetSpace = (IIntermediateNamespaceDeclaration)targetSpace; this.resultInterface = mutableTargetSpace.Parts.Add().Interfaces.Add("I{0}Token", compiler.Source.Options.AssemblyName); this.resultInterface.ImplementedInterfaces.Add(this.rootSymbol.ILanguageSymbol); this.resultInterface.AccessLevel = AccessLevelModifiers.Public; this.BuildStartPosition(); this.BuildEndPosition(); this.BuildStartTokenIndex(); return(this.resultInterface); }
public INamespaceDeclaration this[string path] { get { string ns = path; int lastIndex = 0; CliNamespaceKeyedTree topLevel = this.info; INamespaceDictionary topNamespaceDict = this; StringBuilder pathBuilder = new StringBuilder(); bool first = true; nextPart: int next = ns.IndexOf('.', lastIndex); if (first) { first = false; } else { pathBuilder.Append('.'); } if (next != -1) { string current = ns.Substring(lastIndex, next - lastIndex); pathBuilder.Append(current); uint currentHash = (uint)current.GetHashCode(); if (topLevel.ContainsKey(currentHash)) { topLevel = topLevel[currentHash]; topNamespaceDict = topNamespaceDict[TypeSystemIdentifiers.GetDeclarationIdentifier(pathBuilder.ToString())].Namespaces; } else { return(null); } lastIndex = next + 1; goto nextPart; } else { string current = ns.Substring(lastIndex); pathBuilder.Append(current); uint currentHash = (uint)current.GetHashCode(); if (topLevel.ContainsKey(currentHash)) { topLevel = topLevel[currentHash]; return(topNamespaceDict[TypeSystemIdentifiers.GetDeclarationIdentifier(pathBuilder.ToString())]); } else { return(null); } } } }
protected override IGeneralDeclarationUniqueIdentifier GetIdentifierFrom(int index, uint metadata) { var namespaceInfo = this.info[metadata]; string fullSpace = namespaceInfo.StringsSection[namespaceInfo.Value]; if (namespaceInfo.SubspaceLength != 0) { fullSpace = fullSpace.Substring(0, namespaceInfo.SubspaceStart + namespaceInfo.SubspaceLength); } return(TypeSystemIdentifiers.GetDeclarationIdentifier(fullSpace)); }
public bool ContainsKey(string key) { if (key == null) { throw new ArgumentNullException("key"); } if (key == string.Empty) { throw ThrowHelper.ObtainArgumentException(ArgumentWithException.key, ExceptionMessageId.ArgumentCannotBeEmpty, ThrowHelper.GetArgumentName(ArgumentWithException.key)); } return(this.ContainsKey(TypeSystemIdentifiers.GetDeclarationIdentifier(key))); }
protected override IGeneralDeclarationUniqueIdentifier GetIdentifierFrom(int index, ICliMetadataModuleTableRow metadata) { return(TypeSystemIdentifiers.GetDeclarationIdentifier(metadata.Name)); }
private static void ValidateTypeReferenceTable(IAssembly hostAssembly, ICliMetadataRoot metadataRoot, CompilerErrorCollection resultErrorCollection) { var typeRefTable = metadataRoot.TableStream.TypeRefTable; if (typeRefTable != null) { Parallel.ForEach(typeRefTable.ToArray(), typeRef => { var @namespace = typeRef.Namespace; string fullName = null; if (@namespace == null) { fullName = typeRef.Name; } else { fullName = string.Format("{0}.{1}", @namespace, typeRef.Name); } switch (typeRef.ResolutionScope) { case CliMetadataResolutionScopeTag.Module: if (typeRef.Source == null) { var exportedTypeTable = metadataRoot.TableStream.ExportedTypeTable; if (exportedTypeTable == null) { /* * * When resolution scope is null, there shall be an * ExportedType table row for this type (fullName). * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0101a, hostAssembly, typeRef, new string[] { fullName }); } var exportedType = (from eType in exportedTypeTable where eType.NamespaceIndex == typeRef.NamespaceIndex && eType.NameIndex == typeRef.NameIndex select eType).FirstOrDefault(); if (exportedType == null) { /* * * When resolution scope is null, there shall be an * ExportedType table row for this type (fullName). * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0101a, hostAssembly, metadataRoot, new string[] { fullName }); } } else { /* * * When resolution scope is a module token, the type referenced (fullName) * should be defined within the current module; though, this should not * occur in a CLI ("Compressed Metadata") module. * */ resultErrorCollection.ModelWarning(CliWarningsAndErrors.CliMetadata0101d, hostAssembly, typeRef, new string[] { fullName }); } break; case CliMetadataResolutionScopeTag.ModuleReference: var moduleRef = (ICliMetadataModuleReferenceTableRow)typeRef.Source; if (!hostAssembly.Modules.ContainsKey(TypeSystemIdentifiers.GetDeclarationIdentifier(moduleRef.Name))) { /* * * When resolution scope is a moduleref token, the target type (fullName) * is defined in another module within the same assembly. * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0101c, hostAssembly, typeRef, new string[] { fullName }); } break; case CliMetadataResolutionScopeTag.AssemblyReference: var assemblyReference = (ICliMetadataAssemblyRefTableRow)typeRef.Source; var assemblyUniqueId = CliCommon.GetAssemblyUniqueIdentifier(assemblyReference).Item2; if (assemblyUniqueId == hostAssembly.UniqueIdentifier) { /* * * When resolution scope is an assemblyref, the type referenced (fullName) * should be defined within another assembly other than the current * module's assembly. * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0101e, hostAssembly, typeRef, new string[] { fullName }); } else if (!hostAssembly.References.ContainsKey(assemblyUniqueId)) { hostAssembly.References.ContainsKey(assemblyUniqueId); /* * * When resolution scope is an assemblyref, the type referenced (fullName) * should be defined within another assembly (assemblyUniqueId) which * cannot be found. * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0101f, hostAssembly, typeRef, new string[] { fullName, assemblyUniqueId.ToString() }); } break; case CliMetadataResolutionScopeTag.TypeReference: break; default: break; } if (typeRef.NameIndex == 0 || typeRef.Name == string.Empty) { /* * * Name shall index a non-empty string within the StringHeap. * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0102, hostAssembly, typeRef); } if (typeRef.NamespaceIndex > 0 && typeRef.Namespace == string.Empty) { /* * * Namespace shall index a non-empty string if not null. * */ resultErrorCollection.ModelError(CliWarningsAndErrors.CliMetadata0104, hostAssembly, typeRef); } }); } }
protected override IGeneralTypeUniqueIdentifier OnGetUniqueIdentifier() { if (this.Parent is IType) { return(((IType)this.Parent).UniqueIdentifier.GetNestedIdentifier(this.MetadataEntry.Name, TypeSystemIdentifiers.GetDeclarationIdentifier(this.NamespaceName))); } else if (this.Namespace == null) { return(this.Assembly.UniqueIdentifier.GetTypeIdentifier((IGeneralDeclarationUniqueIdentifier)null, this.MetadataEntry.Name)); } else { return(this.Assembly.UniqueIdentifier.GetTypeIdentifier(this.Namespace.UniqueIdentifier, this.MetadataEntry.Name)); } }