1
////---------------------------------------------------------------------
2
//// Class definition file: PARSENODE.CPP
3
//// Associated header file: PARSENODE.H
5
//// Author: Paul C. Gregory
6
//// Creation date: 18/07/99
7
////---------------------------------------------------------------------
10
#include "parsenode.h"
14
#if defined (AQSIS_SYSTEM_WIN32)
15
#define tolower(x) _tolower(x)
18
START_NAMESPACE( Aqsis )
20
static char* gVariableTypeNames[] =
36
static TqInt gcVariableTypeNames = sizeof( gVariableTypeNames ) / sizeof( gVariableTypeNames[ 0 ] );
38
char* gShaderTypeNames[] =
47
TqInt gcShaderTypeNames = sizeof( gShaderTypeNames ) / sizeof( gShaderTypeNames[ 0 ] );
50
//---------------------------------------------------------------------
51
// Static data on CqParseNode
53
TqInt CqParseNode::m_cLabels = 0;
54
TqInt CqParseNode::m_aaTypePriorities[ Type_Last ][ Type_Last ] =
56
// @ f i p s c t h n v x m
57
/*Type_Nil*/ { 99, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 },
58
/*Type_Float*/ { 00, 99, 98, 02, 00, 01, 02, 02, 02, 02, 00, 01, 00 },
59
/*Type_Integer*/ { 00, 98, 99, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 },
60
/*Type_Point*/ { 00, 00, 00, 99, 00, 96, 98, 98, 97, 97, 00, 00, 00 },
61
/*Type_String*/ { 00, 00, 00, 00, 99, 00, 00, 00, 00, 00, 00, 00, 00 },
62
/*Type_Color*/ { 00, 00, 00, 01, 00, 99, 02, 01, 01, 01, 00, 00, 00 },
63
/*Type_Triple*/ { 00, 00, 00, 98, 00, 98, 99, 97, 98, 98, 00, 00, 00 },
64
/*Type_hPoint*/ { 00, 00, 00, 97, 00, 96, 98, 99, 98, 98, 00, 00, 00 },
65
/*Type_Normal*/ { 00, 00, 00, 98, 00, 96, 98, 97, 99, 98, 00, 00, 00 },
66
/*Type_Vector*/ { 00, 00, 00, 98, 00, 96, 98, 97, 98, 99, 00, 00, 00 },
67
/*Type_Void*/ { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 99, 00, 00 },
68
/*Type_Matrix*/ { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 99, 00 },
69
/*Type_HexTuple*/{ 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 99, 98 },
71
TqInt CqParseNode::m_aAllTypes[ Type_Last - 1 ] =
88
const EqParseNodeType IqParseNode::m_ID = ParseNode_Base;
89
const EqParseNodeType IqParseNodeShader::m_ID = ParseNode_Shader;
90
const EqParseNodeType IqParseNodeFunctionCall::m_ID = ParseNode_FunctionCall;
91
const EqParseNodeType IqParseNodeUnresolvedCall::m_ID = ParseNode_UnresolvedCall;
92
const EqParseNodeType IqParseNodeVariable::m_ID = ParseNode_Variable;
93
const EqParseNodeType IqParseNodeArrayVariable::m_ID = ParseNode_ArrayVariable;
94
const EqParseNodeType IqParseNodeVariableAssign::m_ID = ParseNode_VariableAssign;
95
const EqParseNodeType IqParseNodeArrayVariableAssign::m_ID = ParseNode_ArrayVariableAssign;
96
const EqParseNodeType IqParseNodeOperator::m_ID = ParseNode_Operator;
97
const EqParseNodeType IqParseNodeMathOp::m_ID = ParseNode_MathOp;
98
const EqParseNodeType IqParseNodeRelationalOp::m_ID = ParseNode_RelationalOp;
99
const EqParseNodeType IqParseNodeUnaryOp::m_ID = ParseNode_UnaryOp;
100
const EqParseNodeType IqParseNodeLogicalOp::m_ID = ParseNode_LogicalOp;
101
const EqParseNodeType IqParseNodeDiscardResult::m_ID = ParseNode_DiscardResult;
102
const EqParseNodeType IqParseNodeConstantFloat::m_ID = ParseNode_ConstantFloat;
103
const EqParseNodeType IqParseNodeConstantString::m_ID = ParseNode_ConstantString;
104
const EqParseNodeType IqParseNodeWhileConstruct::m_ID = ParseNode_WhileConstruct;
105
const EqParseNodeType IqParseNodeIlluminateConstruct::m_ID = ParseNode_IlluminateConstruct;
106
const EqParseNodeType IqParseNodeIlluminanceConstruct::m_ID = ParseNode_IlluminanceConstruct;
107
const EqParseNodeType IqParseNodeSolarConstruct::m_ID = ParseNode_SolarConstruct;
108
const EqParseNodeType IqParseNodeConditional::m_ID = ParseNode_Conditional;
109
const EqParseNodeType IqParseNodeConditionalExpression::m_ID = ParseNode_ConditionalExpression;
110
const EqParseNodeType IqParseNodeTypeCast::m_ID = ParseNode_TypeCast;
111
const EqParseNodeType IqParseNodeTriple::m_ID = ParseNode_Triple;
112
const EqParseNodeType IqParseNodeSixteenTuple::m_ID = ParseNode_SixteenTuple;
113
const EqParseNodeType IqParseNodeMessagePassingFunction::m_ID = ParseNode_MessagePassingFunction;
116
///---------------------------------------------------------------------
117
/** Find the shader node, to aid in identifying the shader type.
120
CqParseNodeShader* CqParseNode::pShaderNode()
122
// Search up in the hierarchy.
123
CqParseNode* pShader = this;
124
while( ( NULL != pShader ) && ( pShader->NodeType() != IqParseNodeShader::m_ID ) )
125
pShader = pShader->m_pParent;
126
return( static_cast<CqParseNodeShader*>( pShader ) );
130
///---------------------------------------------------------------------
131
/** Return a string type identifier for the specified type.
134
char* CqParseNode::TypeIdentifier( int Type )
136
return ( gVariableTypeIdentifiers[ Type & Type_Mask ] );
140
///---------------------------------------------------------------------
141
/** Return a type for the specified type identifier.
144
TqInt CqParseNode::TypeFromIdentifier( char Id )
147
for ( i = 0; i < Type_Last; i++ )
149
if ( gVariableTypeIdentifiers[ i ][ 0 ] == Id || gVariableTypeIdentifiers[ i ][ 0 ] == tolower( Id ) )
156
///---------------------------------------------------------------------
157
/** Return a string type name for the specified type.
160
char* CqParseNode::TypeName( int Type )
162
return ( gVariableTypeNames[ Type & Type_Mask ] );
166
///---------------------------------------------------------------------
167
/** Find a valid cast type from the list of available options.
170
TqInt CqParseNode::FindCast( TqInt CurrType, TqInt* pTypes, TqInt Count )
172
// Check if the current type exists in the list first.
174
for ( i = 0; i < Count; i++ )
175
if ( ( pTypes[ i ] & Type_Mask ) == ( CurrType & Type_Mask ) ) return ( static_cast<TqInt>( CurrType & Type_Mask ) );
177
// Else search for the best option.
178
TqInt Ret = Type_Nil;
180
for ( i = 0; i < Count; i++ )
182
if ( m_aaTypePriorities[ CurrType & Type_Mask ][ ( pTypes[ i ] & Type_Mask ) ] > Pri )
185
Pri = m_aaTypePriorities[ CurrType & Type_Mask ][ ( pTypes[ i ] & Type_Mask ) ];
192
///---------------------------------------------------------------------
193
/// CqParseNodeFunctionCall::ResType
195
TqInt CqParseNodeFunctionCall::ResType() const
197
// The return type of a function depends on its arguments.
198
return ( CqFuncDef::GetFunctionPtr( m_aFuncRef[ 0 ] ) ->Type() );
202
const char* CqParseNodeFunctionCall::strName() const
204
CqFuncDef * pFuncDef = CqFuncDef::GetFunctionPtr( m_aFuncRef[ 0 ] );
206
return ( pFuncDef->strName() );
212
const IqFuncDef* CqParseNodeFunctionCall::pFuncDef() const
214
CqFuncDef * pFuncDef = CqFuncDef::GetFunctionPtr( m_aFuncRef[ 0 ] );
222
IqFuncDef* CqParseNodeFunctionCall::pFuncDef()
224
CqFuncDef * pFuncDef = CqFuncDef::GetFunctionPtr( m_aFuncRef[ 0 ] );
232
///---------------------------------------------------------------------
233
/// CqParseNodeUnresolvedCall::ResType
235
TqInt CqParseNodeUnresolvedCall::ResType() const
237
// The return type of a function depends on its arguments.
238
return ( m_aFuncDef.Type() );
242
const char* CqParseNodeUnresolvedCall::strName() const
244
return ( m_aFuncDef.strName() );
248
const IqFuncDef* CqParseNodeUnresolvedCall::pFuncDef() const
250
return ( &m_aFuncDef );
253
IqFuncDef* CqParseNodeUnresolvedCall::pFuncDef()
255
return ( &m_aFuncDef );
259
///---------------------------------------------------------------------
260
/// CqParseNodeVariable::CqParseNodeVariable
262
CqParseNodeVariable::CqParseNodeVariable( SqVarRef VarRef ) :
266
m_fVarying = ( CqVarDef::GetVariablePtr( VarRef ) ->Type() & Type_Varying ) != 0;
270
///---------------------------------------------------------------------
271
/// CqParseNodeVariable::CqParseNodeVariable
273
CqParseNodeVariable::CqParseNodeVariable( CqParseNodeVariable* pVar ) :
275
m_VarRef( pVar->m_VarRef )
277
m_fVarying = ( CqVarDef::GetVariablePtr( m_VarRef ) ->Type() & Type_Varying ) != 0;
281
///---------------------------------------------------------------------
282
/// CqParseNodeVariable::strName
283
/// Returnt the variable name.
285
const char* CqParseNodeVariable::strName() const
287
return ( CqVarDef::GetVariablePtr( m_VarRef ) ->strName() );
291
///---------------------------------------------------------------------
292
/// CqParseNodeVariable::ResType
293
/// Return a string type identifier for this variable.
295
TqInt CqParseNodeVariable::ResType() const
297
IqVarDef * pVD = IqVarDef::GetVariablePtr( m_VarRef );
299
return ( pVD->Type() );
305
///---------------------------------------------------------------------
306
/// CqParseNodeVariableArray::CqParseNodeVariableArray
307
/// Constructor from a variable reference.
309
CqParseNodeVariableArray::CqParseNodeVariableArray( SqVarRef VarRef ) :
310
CqParseNodeVariable( VarRef )
314
///---------------------------------------------------------------------
315
/// CqParseNodeVariableArray::CqParseNodeVariableArray
316
/// Construct from another variable
321
CqParseNodeVariableArray::CqParseNodeVariableArray( CqParseNodeVariableArray* pVar ) :
322
CqParseNodeVariable( pVar )
324
m_fVarying = ( CqVarDef::GetVariablePtr( m_VarRef ) ->Type() & Type_Varying ) != 0;
325
if ( pVar->m_pChild )
326
m_pChild = pVar->m_pChild->Clone( this );
330
///---------------------------------------------------------------------
331
/// CqParseNodeAssign::ResType
332
/// Return a string type identifier for this variable.
334
TqInt CqParseNodeAssign::ResType() const
336
return ( CqVarDef::GetVariablePtr( m_VarRef ) ->Type() );
340
///---------------------------------------------------------------------
341
/// CqParseNodeMathOp::ResType
342
/// Return a string type identifier for this variable.
344
TqInt CqParseNodeMathOp::ResType() const
346
CqParseNode * pOperandA = m_pChild;
347
CqParseNode* pOperandB = m_pChild->pNext();
348
assert( pOperandA != 0 && pOperandB != 0 );
350
TqInt ResAType = pOperandA->ResType();
351
TqInt ResBType = pOperandB->ResType();
353
switch ( m_Operator )
356
return ( Type_Float );
362
// TODO: Should check here for valid types.
363
if ( ( ResAType & Type_Mask ) == Type_Point ||
364
( ResAType & Type_Mask ) == Type_Color )
373
END_NAMESPACE( Aqsis )
374
//---------------------------------------------------------------------