Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ShaderDependencyVisitor.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 using SiliconStudio.Paradox.Shaders.Parser.Ast;
7 using SiliconStudio.Paradox.Shaders.Parser.Utility;
8 using SiliconStudio.Shaders.Ast;
9 using SiliconStudio.Shaders.Ast.Hlsl;
10 using SiliconStudio.Shaders.Utility;
11 using SiliconStudio.Shaders.Visitor;
12 
13 namespace SiliconStudio.Paradox.Shaders.Parser.Mixins
14 {
16  {
17  public HashSet<Tuple<IdentifierGeneric, Node>> FoundIdentifiers = new HashSet<Tuple<IdentifierGeneric, Node>>();
18 
19  public HashSet<string> FoundClasses = new HashSet<string>();
20 
21  private readonly LoggerResult log;
22 
23  /// <summary>
24  /// Name of the classes
25  /// </summary>
26  //private HashSet<string> shaderClassNames;
27  private readonly ShaderSourceManager sourceManager;
28 
30  : base(false, true)
31  {
32  if (log == null) throw new ArgumentNullException("log");
33  if (sourceManager == null) throw new ArgumentNullException("sourceManager");
34 
35  this.log = log;
36  this.sourceManager = sourceManager;
37  }
38 
39  public void Run(ShaderClassType shaderClassType)
40  {
41  Visit(shaderClassType);
42  }
43 
44  [Visit]
45  private void Visit(IdentifierGeneric identifier)
46  {
47  Visit((Node)identifier);
48 
49  FoundIdentifiers.Add(Tuple.Create(identifier, ParentNode));
50  }
51 
52  [Visit]
53  private void Visit(VariableReferenceExpression variableReferenceExpression)
54  {
55  Visit((Node)variableReferenceExpression);
56 
57  if (sourceManager.IsClassExists(variableReferenceExpression.Name.Text))
58  FoundClasses.Add(variableReferenceExpression.Name.Text);
59  }
60 
61  [Visit]
62  private void Visit(MemberReferenceExpression memberReferenceExpression)
63  {
64  Visit((Node)memberReferenceExpression);
65 
66  if (sourceManager.IsClassExists(memberReferenceExpression.Member.Text))
67  FoundClasses.Add(memberReferenceExpression.Member.Text);
68  }
69 
70  [Visit]
71  private void Visit(TypeBase typeBase)
72  {
73  Visit((Node)typeBase);
74 
75  if (sourceManager.IsClassExists(typeBase.Name.Text))
76  {
77  FoundClasses.Add(typeBase.Name.Text);
78  }
79  else if (typeBase is ShaderTypeName)
80  {
81  // Special case for ShaderTypeName as we must generate an error if it is not found
82  log.Error(ParadoxMessageCode.ErrorClassNotFound, typeBase.Span, typeBase.Name.Text);
83  }
84  }
85  }
86 }
string Text
Gets or sets the name.
Definition: Identifier.cs:77
A class to collect parsing/expression messages.
Definition: LoggerResult.cs:13
Abstract node.
Definition: Node.cs:15
ShaderDependencyVisitor(LoggerResult log, ShaderSourceManager sourceManager)
A member reference in the form {this}.{Name}
Base type for all types.
Definition: TypeBase.cs:11
A generic identifier in the form Typename
document false
Identifier Name
Gets or sets the type name.
Definition: TypeBase.cs:77