Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / compiler / translator / ValidateLimitations.h
1 //
2 // Copyright (c) 2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 #include "compiler/translator/IntermNode.h"
8 #include "compiler/translator/LoopInfo.h"
9
10 class TInfoSinkBase;
11
12 // Traverses intermediate tree to ensure that the shader does not exceed the
13 // minimum functionality mandated in GLSL 1.0 spec, Appendix A.
14 class ValidateLimitations : public TIntermTraverser
15 {
16   public:
17     ValidateLimitations(sh::GLenum shaderType, TInfoSinkBase &sink);
18
19     int numErrors() const { return mNumErrors; }
20
21     virtual bool visitBinary(Visit, TIntermBinary *);
22     virtual bool visitUnary(Visit, TIntermUnary *);
23     virtual bool visitAggregate(Visit, TIntermAggregate *);
24     virtual bool visitLoop(Visit, TIntermLoop *);
25
26   private:
27     void error(TSourceLoc loc, const char *reason, const char *token);
28
29     bool withinLoopBody() const;
30     bool isLoopIndex(TIntermSymbol *symbol);
31     bool validateLoopType(TIntermLoop *node);
32
33     bool validateForLoopHeader(TIntermLoop *node);
34     // If valid, return the index symbol id; Otherwise, return -1.
35     int validateForLoopInit(TIntermLoop *node);
36     bool validateForLoopCond(TIntermLoop *node, int indexSymbolId);
37     bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId);
38
39     // Returns true if none of the loop indices is used as the argument to
40     // the given function out or inout parameter.
41     bool validateFunctionCall(TIntermAggregate *node);
42     bool validateOperation(TIntermOperator *node, TIntermNode *operand);
43
44     // Returns true if indexing does not exceed the minimum functionality
45     // mandated in GLSL 1.0 spec, Appendix A, Section 5.
46     bool isConstExpr(TIntermNode *node);
47     bool isConstIndexExpr(TIntermNode *node);
48     bool validateIndexing(TIntermBinary *node);
49
50     sh::GLenum mShaderType;
51     TInfoSinkBase &mSink;
52     int mNumErrors;
53     TLoopStack mLoopStack;
54 };
55