blob: ddbefc5619740a60e97801a90dcc2fa17405d044 [file] [log] [blame]
Olli Etuahoac5274d2015-02-20 10:19:08 +02001//
2// Copyright (c) 2002-2015 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#ifndef COMPILER_TRANSLATOR_VALIDATESWITCH_H_
8#define COMPILER_TRANSLATOR_VALIDATESWITCH_H_
9
10#include "compiler/translator/IntermNode.h"
11
Jamie Madill6e06b1f2015-05-14 10:01:17 -040012class TParseContext;
Olli Etuahoac5274d2015-02-20 10:19:08 +020013
14class ValidateSwitch : public TIntermTraverser
15{
16 public:
17 // Check for errors and output messages any remaining errors on the context.
18 // Returns true if there are no errors.
19 static bool validate(TBasicType switchType, TParseContext *context,
20 TIntermAggregate *statementList, const TSourceLoc &loc);
21
22 void visitSymbol(TIntermSymbol *) override;
23 void visitConstantUnion(TIntermConstantUnion *) override;
24 bool visitBinary(Visit, TIntermBinary *) override;
25 bool visitUnary(Visit, TIntermUnary *) override;
26 bool visitSelection(Visit visit, TIntermSelection *) override;
27 bool visitSwitch(Visit, TIntermSwitch *) override;
28 bool visitCase(Visit, TIntermCase *node) override;
29 bool visitAggregate(Visit, TIntermAggregate *) override;
30 bool visitLoop(Visit visit, TIntermLoop *) override;
31 bool visitBranch(Visit, TIntermBranch *) override;
32
33 private:
34 ValidateSwitch(TBasicType switchType, TParseContext *context);
35
36 bool validateInternal(const TSourceLoc &loc);
37
38 TBasicType mSwitchType;
39 TParseContext *mContext;
40 bool mCaseTypeMismatch;
41 bool mFirstCaseFound;
42 bool mStatementBeforeCase;
43 bool mLastStatementWasCase;
44 int mControlFlowDepth;
45 bool mCaseInsideControlFlow;
46 int mDefaultCount;
47 std::set<int> mCasesSigned;
48 std::set<unsigned int> mCasesUnsigned;
49 bool mDuplicateCases;
50};
51
52#endif // COMPILER_TRANSLATOR_VALIDATESWITCH_H_