/// <summary> /// Initializes a new instance of the <see cref="TypeBase"/> class. /// </summary> /// <param name="name"> /// The name. /// </param> protected TypeBase(Identifier name) { Name = name; Attributes = new List<AttributeBase>(); Qualifiers = Qualifier.None; TypeInference = new TypeInference(); }
/// <summary> /// Initializes a new instance of the <see cref="GenericDeclaration"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="holder">The holder.</param> /// <param name="index">The index.</param> /// <param name="isUsingBase">if set to <c>true</c> [is using base].</param> public GenericDeclaration(Identifier name, IGenerics holder, int index, bool isUsingBase) { Name = name; Holder = holder; Index = index; IsUsingBase = isUsingBase; }
/// <summary> /// Initializes a new instance of the <see cref="Variable"/> class. /// </summary> /// <param name="type">The type.</param> /// <param name="name">The name.</param> /// <param name="initialValue">The initial value.</param> public Variable(TypeBase type, string name, Expression initialValue = null) { Type = type; Name = new Identifier(name); InitialValue = initialValue; Attributes = new List<AttributeBase>(); Qualifiers = Qualifier.None; }
protected static void ParseClassGenerics(Identifier input, ShaderClassType dest) { // Parse generic identifier and convert it to simple identifier by adding contraint to the class type var genericIdentifier = input as ClassIdentifierGeneric; if (genericIdentifier != null) { foreach (var genericIdentifierItem in genericIdentifier.Generics) { dest.ShaderGenerics.Add(genericIdentifierItem); } input = new Identifier(input.Text) { Span = genericIdentifier.Span }; } dest.Name = input; }
public virtual void Visit(Identifier identifier) { Write(identifier); }
/// <summary> /// Initializes a new instance of the <see cref="ShaderTypeName"/> class. /// </summary> /// <param name="name">The name.</param> public ShaderTypeName(Identifier name) : base(name) { }
/// <summary> /// Initializes a new instance of the <see cref="VariableReferenceExpression"/> class. /// </summary> /// <param name="name">The name.</param> public VariableReferenceExpression(Identifier name) { Name = name; }
/// <summary> /// Helper function to get the complete name of an identifier /// </summary> /// <param name="identifier">the identifier</param> /// <returns>the identifier name</returns> private static string GetIdentifierName(Identifier identifier) { string genericName; if (identifier is LiteralIdentifier) genericName = (identifier as LiteralIdentifier).Value.Value.ToString(); else if (identifier is IdentifierDot) { var idDot = identifier as IdentifierDot; genericName = idDot.Identifiers.Aggregate("", (current, id) => current + (GetIdentifierName(id) + idDot.Separator)); genericName = genericName.Substring(0, genericName.Length - idDot.Separator.Length); } else genericName = identifier.Text; if (genericName == null) throw new Exception(string.Format("Unable to find the name of the generic [{0}]", identifier)); return genericName; }
/// <summary> /// Initializes a new instance of the <see cref="ParametersBlock" /> class. /// </summary> /// <param name="name">The name.</param> /// <param name="statements">The statements.</param> public ParametersBlock(Identifier name, BlockStatement statements) { Name = name; Body = statements; }
/// <summary> /// Build the ModuleMixinInfo class /// </summary> /// <param name="shaderSource">the ShaderSource to load</param> /// <param name="macros">the macros applied on the source</param> /// <returns>the ModuleMixinInfo</returns> private ModuleMixinInfo BuildMixinInfo(ShaderSource shaderSource, SiliconStudio.Shaders.Parser.ShaderMacro[] macros) { ModuleMixinInfo mixinInfo = null; if (shaderSource is ShaderClassSource) { var shaderClassSource = shaderSource as ShaderClassSource; mixinInfo = new ModuleMixinInfo { ShaderSource = shaderClassSource, Macros = macros }; LoadMixinFromClassSource(mixinInfo); } else if (shaderSource is ShaderMixinSource) { var shaderMixinSource = shaderSource as ShaderMixinSource; var shaderName = "Mix" + lastMixIndex; ++lastMixIndex; var fakeAst = new ShaderClassType(shaderName); foreach (var classSource in shaderMixinSource.Mixins) { Identifier name; if (classSource.GenericArguments != null && classSource.GenericArguments.Length > 0) name = new IdentifierGeneric(classSource.ClassName, classSource.GenericArguments.Select(x => new Identifier(x.ToString())).ToArray()); else name = new Identifier(classSource.ClassName); fakeAst.BaseClasses.Add(new TypeName(name)); } mixinInfo = new ModuleMixinInfo { MixinGenericName = shaderName, Macros = macros, MixinAst = fakeAst, ShaderSource = shaderSource, SourceHash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(shaderName)), Instanciated = true }; } return mixinInfo; }
/// <summary> /// Loads generic classes that may appear in the mixin /// </summary> /// <param name="mixinInfo">The mixin to investigate</param> /// <param name="macros">The macros.</param> /// <param name="macrosString">The macros string.</param> private void LoadNecessaryShaders(ModuleMixinInfo mixinInfo, SiliconStudio.Shaders.Parser.ShaderMacro[] macros, string macrosString) { if (!mixinInfo.Instanciated) return; // Look for all the generic calls var shaderDependencyVisitor = new ShaderDependencyVisitor(mixinInfo.Log, ShaderLoader.SourceManager); shaderDependencyVisitor.Run(mixinInfo.MixinAst); foreach (var foundClass in shaderDependencyVisitor.FoundClasses) { var classSource = new ShaderClassSource(foundClass, null); var foundMixinInfo = GetModuleMixinInfo(classSource, macros, macrosString); mixinInfo.MinimalContext.UnionWith(foundMixinInfo.MinimalContext); } foreach (var id in shaderDependencyVisitor.FoundIdentifiers) { var genericClass = id.Item1; ModuleMixinInfo.CleanIdentifiers(genericClass.Identifiers); var genericParams = BuildShaderGenericParameters(genericClass); var classSource = new ShaderClassSource(genericClass.Text, genericParams); var instanciatedClassInfo = GetModuleMixinInfo(classSource, macros, macrosString); mixinInfo.MinimalContext.UnionWith(instanciatedClassInfo.MinimalContext); var newId = new Identifier(instanciatedClassInfo.MixinName); if (id.Item2 is TypeName) // in the baseclass list or in a variable declaration (id.Item2 as TypeName).Name = newId; else if (id.Item2 is VariableReferenceExpression) (id.Item2 as VariableReferenceExpression).Name = newId; else if (id.Item2 is MemberReferenceExpression) (id.Item2 as MemberReferenceExpression).Member = newId; } }
/// <summary> /// Initializes a new instance of the <see cref="GenericParameterType"/> class. /// </summary> /// <param name="name">The name.</param> public GenericParameterType(Identifier name) : base(name) { }
/// <summary> /// Initializes a new instance of the <see cref="TypeName"/> class. /// </summary> /// <param name="name">The name.</param> public TypeName(Identifier name) : base(name) { }
/// <summary> /// Writes the specified identifier. /// </summary> /// <param name="identifier"> /// The identifier. /// </param> /// <returns> /// This instance /// </returns> protected virtual ShaderWriter Write(Identifier identifier) { if (identifier.IsSpecialReference) Write("<"); Write(identifier.Text); if (identifier.HasIndices) WriteRankSpecifiers(identifier.Indices); if (identifier.IsSpecialReference) Write(">"); return this; }
/// <summary> /// Initializes a new instance of the <see cref="MemberReferenceExpression"/> class. /// </summary> /// <param name="this">The @this.</param> /// <param name="member">The member.</param> public MemberReferenceExpression(Expression @this, string member) { Target = @this; Member = new Identifier(member); }
/// <summary> /// Initializes a new instance of the <see cref="MemberReferenceExpression"/> class. /// </summary> /// <param name="this">The @this.</param> /// <param name="member">The member.</param> public MemberReferenceExpression(Expression @this, Identifier member) { Target = @this; Member = member; }
private bool TryParameters(Expression expression, out Identifier type, out Identifier member) { type = null; member = null; var memberReferenceExpression = expression as MemberReferenceExpression; if (memberReferenceExpression == null) return false; var name = memberReferenceExpression.Target as VariableReferenceExpression; bool foundDeclaredParameters = false; if (currentBlock != null) { var context = (ShaderBlockContext)currentBlock.GetTag(BlockContextTag); HashSet<string> usings = context.DeclaredParameters; if (name != null && usings.Contains(name.Name)) { type = name.Name; member = memberReferenceExpression.Member; foundDeclaredParameters = true; } } return foundDeclaredParameters; }
private void AddPushPopParameters(BlockStatement blockStatement, Identifier parameterType, Identifier parameterMember, Expression paramValue, SourceSpan span) { var pushStatement = new ExpressionStatement(new MethodInvocationExpression(new MemberReferenceExpression(new VariableReferenceExpression("context"), "PushParameters"), paramValue)) {Span = span}; var popStatement = new ExpressionStatement(new MethodInvocationExpression(new MemberReferenceExpression(new VariableReferenceExpression("context"), "PopParameters"))) {Span = span}; blockStatement.Statements.Insert(0, pushStatement); ; blockStatement.Statements.Add(popStatement); }
/// <summary> /// Writes the specified identifier. /// </summary> /// <param name="identifier">The identifier.</param> /// <returns> /// This instance /// </returns> protected override ShaderWriter Write(Identifier identifier) { Write(identifier.Text); if (identifier.IsSpecialReference) { Write("<"); } if (identifier is CompositeIdentifier) { var compositeIdentifier = (CompositeIdentifier)identifier; for (int i = 0; i < compositeIdentifier.Identifiers.Count; i++) { var subIdentifier = compositeIdentifier.Identifiers[i]; if (i > 0) Write(compositeIdentifier.Separator); Write(subIdentifier); } } if (identifier.HasIndices) { WriteRankSpecifiers(identifier.Indices); } if (identifier.IsSpecialReference) { Write(">"); } return this; }
/// <inheritdoc /> public override void Visit(Identifier identifier) { Write(identifier); }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other"> /// The other. /// </param> /// <returns> /// true if equals to other. /// </returns> public bool Equals(Identifier other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return Equals(other.Text, this.Text) && other.IsSpecialReference.Equals(this.IsSpecialReference); }
/// <summary> /// Initializes a new instance of the <see cref="MethodDefinition"/> class. /// </summary> /// <param name="returntype">The returntype.</param> /// <param name="name">The name.</param> public MethodDefinition(TypeBase returntype, string name) : this() { ReturnType = returntype; Name = new Identifier(name); declaration = this; }
/// <summary> /// Initializes a new instance of the <see cref="KeywordExpression"/> class. /// </summary> /// <param name="name"> /// The name. /// </param> public KeywordExpression(Identifier name) { Name = name; }