public override Node Visit(TypeName typeName) { var newTypeName = (TypeBase)base.Visit(typeName); if (newTypeName.TypeInference.Declaration != null) { parsingInfo.NavigableNodes.Add(typeName); } return newTypeName; }
/// <summary> /// Visits the specified type. /// </summary> /// <param name="typeName">the type.</param> public override void Visit(TypeName typeName) { var type = typeName.ResolveType(); if (ReferenceEquals(typeName, type)) { base.Visit(typeName); ProcessInitialValueStatus = true; } else { VisitDynamic(type); } }
public virtual void Visit(TypeName typeBase) { Write(typeBase.Name); }
/// <inheritdoc /> public override void Visit(TypeName typeBase) { Write(typeBase.Name); }
public override TypeBase ToNonGenericType(SourceSpan? span = null) { var typeName = new TypeName(); var name = string.Format("{0}{1}", Type.Name, Dimension); typeName.Name = new Identifier(name); if (span.HasValue) { typeName.Span = span.Value; typeName.Name.Span = span.Value; }; typeName.TypeInference.TargetType = this; return typeName; }
protected override TypeBase Visit(TypeName typeName) { Visit((Node)typeName); var name = typeName.Name.Text; // Substitute case insensitive types to case sensitive types // TODO this is temporary. We need to found a better workaround. TypeBase value = TextureType.Parse(name); if (value != null) { AssociatePredefinedObjects(value); return value; } value = StreamTypeName.Parse(name); if (value != null) { AssociatePredefinedObjects(value); return value; } value = SamplerType.Parse(name); if (value != null) return value; value = StateType.Parse(name); if (value != null) return value; // Replace shader objects if (name == "VertexShader" || name == "GeometryShader" || name == "PixelShader") return new ObjectType(name); // Else call the base return base.Visit(typeName); }
protected virtual TypeBase Visit(TypeName typeName) { Visit((Node)typeName); if (typeName.TypeInference.TargetType == null) { if (typeName.Name.Text == "void") { typeName.TypeInference.TargetType = TypeBase.Void; } else if (typeName.Name.Text == "string") { typeName.TypeInference.TargetType = TypeBase.String; } else { var declaration = FindDeclaration(typeName.Name); if (declaration != null) { // Setup a type reference for this typeName var typeReference = typeName.TypeInference; typeReference.Declaration = declaration; typeReference.TargetType = ResolveTypeFromDeclaration(typeReference.Declaration); } else { Error(MessageCode.ErrorNoTypeReferenceTypename, typeName.Span, typeName); } } } return typeName; }
/// <summary> /// rename the input/ouput of a method /// </summary> /// <param name="methodDeclaration">the method</param> /// <param name="inputName">the type replacement for Input</param> /// <param name="input2Name">the type replacement for Input2</param> /// <param name="outputName">the type replacement for Output</param> /// <param name="constantsName">the type replacement for Constants</param> private void RenameInputOutput(MethodDeclaration methodDeclaration, TypeName inputName, TypeName input2Name, TypeName outputName, TypeName constantsName) { if (inputName != null) { var replacor = new ParadoxReplaceVisitor(StreamsType.Input, inputName); replacor.Run(methodDeclaration); } if (input2Name != null) { var replacor = new ParadoxReplaceVisitor(StreamsType.Input2, input2Name); replacor.Run(methodDeclaration); } if (outputName != null) { var replacor = new ParadoxReplaceVisitor(StreamsType.Output, outputName); replacor.Run(methodDeclaration); } if (constantsName != null) { var replacor = new ParadoxReplaceVisitor(StreamsType.Constants, constantsName); replacor.Run(methodDeclaration); } }
/// <summary> /// Recursively rename the input/output types /// </summary> /// <param name="methodDeclaration">the method to explore</param> /// <param name="inputName">the TypeName for Input</param> /// <param name="input2Name">the TypeName for Input2</param> /// <param name="outputName">the TypeName for Output</param> /// <param name="constantsName">the TypeName for Constants</param> /// <param name="visitedMethods">the already visited methods</param> private void RecursiveRename(MethodDeclaration methodDeclaration, TypeName inputName, TypeName input2Name, TypeName outputName, TypeName constantsName, Stack<MethodDeclaration> visitedMethods) { if (methodDeclaration == null || visitedMethods.Contains(methodDeclaration)) return; RenameInputOutput(methodDeclaration, inputName, input2Name, outputName, constantsName); visitedMethods.Push(methodDeclaration); List<MethodDeclaration> calls; if (TryGetMethodCalls(methodDeclaration, out calls)) { foreach (var calledmethod in calls) RecursiveRename(calledmethod, inputName, input2Name, outputName, constantsName, visitedMethods); } }
/// <summary> /// Modify the Hull shader constant /// </summary> /// <param name="entryPoint">the entrypoint method</param> /// <param name="inStreamStructTypeName">the input structure of the Hull shader</param> /// <param name="outStreamStructTypeName">the output structure of the Hull shader</param> private void GenerateStreamsForHullShaderConstant(MethodDefinition entryPoint, TypeName inStreamStructTypeName, TypeName outStreamStructTypeName) { if (entryPoint != null) { var constStreamStruct = CreateStreamStructure(mainModuleMixin.VirtualTable.Variables.Select(x => x.Variable).Where(x => x.Qualifiers.Contains(ParadoxStorageQualifier.PatchStream)).Distinct().ToList<IDeclaration>(), "HS_CONSTANTS"); var typeConst = new TypeName(constStreamStruct.Name); var visitedMethods = new Stack<MethodDeclaration>(); RecursiveRename(entryPoint, inStreamStructTypeName, outStreamStructTypeName, outStreamStructTypeName, typeConst, visitedMethods); // get the Constants parameter, its name and remove it var constParamName = "constants"; var constParam = entryPoint.Parameters.FirstOrDefault(x => x.Type.Name.Text == constStreamStruct.Name.Text); if (constParam != null) { constParamName = constParam.Name.Text; entryPoint.Parameters.Remove(constParam); // remove the parameter } var constDecl = new DeclarationStatement( new Variable(typeConst, constParamName) { InitialValue = new CastExpression { From = new LiteralExpression(0), Target = new TypeName(constStreamStruct.Name) } }); entryPoint.Body.Insert(0, constDecl); // insert structure instance declaration entryPoint.Body.Add(new ReturnStatement(new VariableReferenceExpression(constParamName))); // add a return statement entryPoint.ReturnType = typeConst; // change the return type shader.Members.Insert(0, constStreamStruct); } }
/// <summary> /// Generates a stream structure and add them to the Ast - for the hull shader and hull shader constant /// </summary> /// <param name="entryPoint">the entrypoint function</param> /// <param name="entryPointHSConstant">entrypoint for the hull shader constant</param> /// <param name="streamStageUsage">the stream usage in this stage</param> /// <param name="stageName">the name of the stage</param> /// <param name="prevOuputStructure">the output structutre from the previous stage</param> /// <returns>the new output structure</returns> private StructType GenerateStreamsForHullShader(MethodDefinition entryPoint, MethodDefinition entryPointHSConstant, StreamStageUsage streamStageUsage, string stageName, StructType prevOuputStructure) { if (entryPoint != null) { // same behavior as geometry shader var outStreamStruct = GenerateStreamsWithSpecialDataInput(entryPoint, streamStageUsage, stageName, prevOuputStructure); var inStreamStruct = prevOuputStructure ?? shader.Members.OfType<StructType>().FirstOrDefault(x => x.Name.Text == stageName + "_INPUT"); var intermediateStreamStruct = shader.Members.OfType<StructType>().FirstOrDefault(x => x.Name.Text == stageName + "_STREAMS"); if (inStreamStruct == null) throw new Exception("inStreamStruct cannot be null"); var inStructType = new TypeName(inStreamStruct.Name); var outStructType = new TypeName(outStreamStruct.Name); // get the Output parameter, its name and remove it var outputName = "output"; var outputParam = entryPoint.Parameters.FirstOrDefault(x => x.Type.Name.Text == outStreamStruct.Name.Text); if (outputParam != null) { outputName = outputParam.Name.Text; // get the name of the parameter entryPoint.Parameters.Remove(outputParam); // remove the parameter } entryPoint.Body.Add(new ReturnStatement { Value = new VariableReferenceExpression(outputName) }); entryPoint.Body.Insert(0, CreateStructInit(outStreamStruct, outputName)); entryPoint.ReturnType = outStructType; if (entryPointHSConstant != null) GenerateStreamsForHullShaderConstant(entryPointHSConstant, inStructType, outStructType); return outStreamStruct; } return prevOuputStructure; }
/// <summary> /// Generates a stream structure and add them to the Ast - for the geometry shader /// </summary> /// <param name="entryPoint">the entrypoint function</param> /// <param name="streamStageUsage">the stream usage in this stage</param> /// <param name="stageName">the name of the stage</param> /// <param name="prevOuputStructure">the output structutre from the previous stage</param> /// <returns>the new output structure</returns> private StructType GenerateStreamsWithSpecialDataInput(MethodDefinition entryPoint, StreamStageUsage streamStageUsage, string stageName, StructType prevOuputStructure) { if (entryPoint != null) { var inStreamStruct = prevOuputStructure ?? CreateStreamStructure(streamStageUsage.InStreamList, stageName + "_INPUT"); var outStreamStruct = CreateStreamStructure(streamStageUsage.OutStreamList, stageName + "_OUTPUT"); var mixin = entryPoint.GetTag(ParadoxTags.ShaderScope) as ModuleMixin; var intermediateStreamStruct = CreateIntermediateStructType(streamStageUsage, stageName); // put the streams declaration at the beginning of the method body var streamsDeclaration = new DeclarationStatement(new Variable(new TypeName(intermediateStreamStruct.Name), "streams") { InitialValue = new CastExpression { From = new LiteralExpression(0), Target = new TypeName(intermediateStreamStruct.Name) } }); entryPoint.Body.Insert(0, streamsDeclaration); // add the declaration statements to the entrypoint and fill with the values var outputStatements = CreateOutputFromStream(outStreamStruct, "output", intermediateStreamStruct, "streams").ToList(); var outputVre = new VariableReferenceExpression(((outputStatements.First() as DeclarationStatement).Content as Variable).Name); var replacor = new ParadoxReplaceAppend(streamAnalyzer.AppendMethodCalls, outputStatements, outputVre); ReplaceAppendMethod(entryPoint, replacor); var visitedMethods = new Stack<MethodDeclaration>(); var inStructType = new TypeName(inStreamStruct.Name); var outStructType = new TypeName(outStreamStruct.Name); RecursiveRename(entryPoint, inStructType, null, outStructType, null, visitedMethods); // explore all the called functions var streamsVisitedMethods = new HashSet<MethodDeclaration>(); var methodsWithStreams = new List<MethodDeclaration>(); PropagateStreamsParameter(entryPoint, inStreamStruct, intermediateStreamStruct, outStreamStruct, streamsVisitedMethods, methodsWithStreams); CheckCrossStageMethodCall(streamStageUsage.ShaderStage, methodsWithStreams); if (prevOuputStructure == null) shader.Members.Insert(0, inStreamStruct); shader.Members.Insert(0, outStreamStruct); shader.Members.Insert(0, intermediateStreamStruct); return outStreamStruct; } return prevOuputStructure; }