~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libslparse/libslparse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Implements the entrypoint for the shader compiler.
 
23
                \author Paul C. Gregory (pgregory@aqsis.com)
 
24
*/
 
25
 
 
26
#include "libslparse.h"
 
27
#include "parsenode.h"
 
28
 
 
29
extern int yyparse();
 
30
 
 
31
START_NAMESPACE( Aqsis )
 
32
 
 
33
 
 
34
 
 
35
extern CqParseNode* ParseTreePointer;
 
36
extern void TypeCheck();
 
37
extern void Optimise();
 
38
extern void InitStandardNamespace();
 
39
 
 
40
 
 
41
std::istream* ParseInputStream = &std::cin;
 
42
CqString ParseStreamName = "stdin";
 
43
std::ostream* ParseErrorStream = &std::cerr;
 
44
TqInt ParseLineNumber;
 
45
TqBool ParseSucceeded = true;
 
46
 
 
47
TqBool Parse( std::istream& InputStream, const CqString StreamName, std::ostream& ErrorStream )
 
48
{
 
49
    ParseInputStream = &InputStream;
 
50
    ParseStreamName = StreamName;
 
51
    ParseErrorStream = &ErrorStream;
 
52
    ParseLineNumber = 1;
 
53
    ParseSucceeded = true;
 
54
 
 
55
    InitStandardNamespace();
 
56
 
 
57
    try
 
58
    {
 
59
        yyparse();
 
60
        TypeCheck();
 
61
    }
 
62
    catch(CqString error)
 
63
    {
 
64
        ( *ParseErrorStream ) << error.c_str() << std::endl;
 
65
        ( *ParseErrorStream ) << "ERROR: Shader not compiled" << std::endl;
 
66
        ParseSucceeded = false;
 
67
        return( false );
 
68
    }
 
69
    Optimise();
 
70
 
 
71
    std::vector<CqVarDef>::iterator iv;
 
72
    for ( iv = gLocalVars.begin(); iv != gLocalVars.end(); iv++ )
 
73
        if ( iv->pDefValue() ) iv->pDefValue() ->Optimise();
 
74
 
 
75
    return ParseSucceeded;
 
76
}
 
77
 
 
78
void ResetParser()
 
79
{
 
80
    ParseInputStream = &std::cin;
 
81
    ParseStreamName = "stdin";
 
82
    ParseErrorStream = &std::cerr;
 
83
    ParseLineNumber = 1;
 
84
    ParseSucceeded = true;
 
85
}
 
86
 
 
87
 
 
88
IqParseNode* GetParseTree()
 
89
{
 
90
    return ( ParseTreePointer );
 
91
}
 
92
 
 
93
END_NAMESPACE( Aqsis )
 
94
 
 
95
//-------------------------------------------------------------