3 using System.Collections.Generic;
6 using SiliconStudio.Paradox.Shaders.Parser.Ast;
7 using SiliconStudio.Paradox.Shaders.Parser.Utility;
8 using SiliconStudio.Shaders.Ast;
9 using SiliconStudio.Shaders.Utility;
11 namespace SiliconStudio.
Paradox.Shaders.Parser.Mixins
13 internal class ShaderVirtualTable
17 public Dictionary<string, MethodDeclaration[]> VirtualTableGroup =
new Dictionary<string, MethodDeclaration[]>();
23 public ShaderVirtualTable() {}
27 #region Public methods
35 public void AddVirtualTable(ShaderVirtualTable shaderVirtualTable,
string className,
LoggerResult errorLogger)
37 var newVT = shaderVirtualTable.VirtualTableGroup[className].ToArray();
38 VirtualTableGroup.Add(className, newVT);
40 foreach (var methodDecl
in newVT)
41 ReplaceVirtualMethod(methodDecl, errorLogger);
52 foreach (var dict
in VirtualTableGroup.Select(x => x.Value))
54 for (
int i = 0; i < dict.Length; ++i)
60 if (originalDecl == baseDeclarationMixin && method.IsSameSignature(methodDeclaration))
64 errorLogger.Warning(ParadoxMessageCode.WarningMissingStageKeyword, methodDeclaration.Span, methodDeclaration, (methodDeclaration.GetTag(ParadoxTags.ShaderScope) as ModuleMixin).MixinName);
65 methodDeclaration.Qualifiers |= ParadoxStorageQualifier.Stage;
67 else if (!method.Qualifiers.Contains(
ParadoxStorageQualifier.
Stage) && methodDeclaration.Qualifiers.Contains(ParadoxStorageQualifier.Stage))
69 errorLogger.Error(ParadoxMessageCode.ErrorExtraStageKeyword, methodDeclaration.Span, methodDeclaration, method, (methodDeclaration.GetTag(ParadoxTags.ShaderScope) as ModuleMixin).MixinName);
70 methodDeclaration.Qualifiers.Values.Remove(ParadoxStorageQualifier.Stage);
73 dict[i] = methodDeclaration;
85 public void AddFinalDeclarations(List<MethodDeclaration> methodDeclarations,
string className,
LoggerResult errorLogger)
88 foreach (var methodDecl
in methodDeclarations)
91 finalDict[vtableReference.Slot] = methodDecl;
95 LookForBaseDeclarationMixin(methodDecl, errorLogger);
98 VirtualTableGroup.Add(className, finalDict);
108 var baseMethodDeclMixin = methodDeclaration.GetTag(ParadoxTags.BaseDeclarationMixin) as
string;
110 var vt = VirtualTableGroup[baseMethodDeclMixin];
111 for (
int i = 0; i < vt.Length; ++i)
119 return new VTableReference {
Shader = baseMethodDeclMixin, Slot = slot };
131 if (VirtualTableGroup.TryGetValue(mixinName, out decls))
133 if (decls.Length > slot)
134 return VirtualTableGroup[mixinName][slot];
141 #region Private methods
150 foreach (var dict
in VirtualTableGroup.Select(x => x.Value))
152 for (
int i = 0; i < dict.Length; ++i)
154 var method = dict[i];
158 if (method.IsSameSignature(methodDeclaration))
166 errorLogger.Error(ParadoxMessageCode.ErrorOverrindingDeclaration, method.Span, methodDeclaration, sourceShader);
170 errorLogger.Warning(ParadoxMessageCode.WarningMissingStageKeyword, methodDeclaration.Span, methodDeclaration, (methodDeclaration.GetTag(ParadoxTags.ShaderScope) as ModuleMixin).MixinName);
171 methodDeclaration.Qualifiers |= ParadoxStorageQualifier.Stage;
173 else if (!method.Qualifiers.Contains(
ParadoxStorageQualifier.
Stage) && methodDeclaration.Qualifiers.Contains(ParadoxStorageQualifier.Stage))
175 errorLogger.Error(ParadoxMessageCode.ErrorExtraStageKeyword, methodDeclaration.Span, methodDeclaration, method, (methodDeclaration.GetTag(ParadoxTags.ShaderScope) as ModuleMixin).MixinName);
176 methodDeclaration.Qualifiers.Values.Remove(ParadoxStorageQualifier.Stage);
179 dict[i] = methodDeclaration;
180 methodDeclaration.SetTag(ParadoxTags.BaseDeclarationMixin, baseDeclarationMixin);
void Error(MessageCode message, SourceSpan span)
Logs an Error with the specified message.
A class to collect parsing/expression messages.
static readonly SiliconStudio.Shaders.Ast.StorageQualifier Override
Override keyword (override).
A method definition with a body of statements.
bool IsSameSignature(MethodDeclaration methodDeclaration)
Test if a method declaration has the same signature.
static readonly MessageCode ErrorMissingOverride
static readonly SiliconStudio.Shaders.Ast.StorageQualifier Stage
Stage keyword (stage).
Toplevel container of a shader parsing result.
bool Contains(CompositeEnum enumValue)
Determines whether [contains] [the specified enum value].
Qualifier Qualifiers
Gets or sets the storage class.
object GetTag(object tagKey)
Gets a tag value associated to this node..