Support suffixes for floats and doubles (none were supported in 110).
Add preprocessor support for parsing doubles. Add double support to the flex stage. Put in some of the basic double supported needed in the front end. Add generic support for version numbers in the preprocessor, and the core, compatibility, and es profiles. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@19949 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
e95ecc54fa
commit
5d3e2e35b6
@ -41,6 +41,7 @@
|
|||||||
enum TBasicType {
|
enum TBasicType {
|
||||||
EbtVoid,
|
EbtVoid,
|
||||||
EbtFloat,
|
EbtFloat,
|
||||||
|
EbtDouble,
|
||||||
EbtInt,
|
EbtInt,
|
||||||
EbtBool,
|
EbtBool,
|
||||||
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
|
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
|
||||||
|
@ -42,13 +42,16 @@ public:
|
|||||||
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
||||||
void setIConst(int i) {iConst = i; type = EbtInt; }
|
void setIConst(int i) {iConst = i; type = EbtInt; }
|
||||||
void setFConst(float f) {fConst = f; type = EbtFloat; }
|
void setFConst(float f) {fConst = f; type = EbtFloat; }
|
||||||
|
void setDConst(double d) {dConst = d; type = EbtDouble; }
|
||||||
void setBConst(bool b) {bConst = b; type = EbtBool; }
|
void setBConst(bool b) {bConst = b; type = EbtBool; }
|
||||||
|
|
||||||
int getIConst() { return iConst; }
|
int getIConst() { return iConst; }
|
||||||
float getFConst() { return fConst; }
|
float getFConst() { return fConst; }
|
||||||
|
double getDConst() { return dConst; }
|
||||||
bool getBConst() { return bConst; }
|
bool getBConst() { return bConst; }
|
||||||
int getIConst() const { return iConst; }
|
int getIConst() const { return iConst; }
|
||||||
float getFConst() const { return fConst; }
|
float getFConst() const { return fConst; }
|
||||||
|
double getDConst() const { return dConst; }
|
||||||
bool getBConst() const { return bConst; }
|
bool getBConst() const { return bConst; }
|
||||||
|
|
||||||
bool operator==(const int i) const
|
bool operator==(const int i) const
|
||||||
@ -67,6 +70,14 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const double d) const
|
||||||
|
{
|
||||||
|
if (d == dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const bool b) const
|
bool operator==(const bool b) const
|
||||||
{
|
{
|
||||||
if (b == bConst)
|
if (b == bConst)
|
||||||
@ -90,6 +101,11 @@ public:
|
|||||||
if (constant.fConst == fConst)
|
if (constant.fConst == fConst)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EbtDouble:
|
||||||
|
if (constant.dConst == dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EbtBool:
|
case EbtBool:
|
||||||
if (constant.bConst == bConst)
|
if (constant.bConst == bConst)
|
||||||
@ -134,6 +150,11 @@ public:
|
|||||||
if (fConst > constant.fConst)
|
if (fConst > constant.fConst)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtDouble:
|
||||||
|
if (dConst > constant.dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
assert(false && "Default missing");
|
assert(false && "Default missing");
|
||||||
@ -156,6 +177,11 @@ public:
|
|||||||
if (fConst < constant.fConst)
|
if (fConst < constant.fConst)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case EbtDouble:
|
||||||
|
if (dConst < constant.dConst)
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
assert(false && "Default missing");
|
assert(false && "Default missing");
|
||||||
@ -172,6 +198,7 @@ public:
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
||||||
case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
|
case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
|
||||||
|
case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
|
||||||
default: assert(false && "Default missing");
|
default: assert(false && "Default missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +212,7 @@ public:
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
||||||
case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
|
case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
|
||||||
|
case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
|
||||||
default: assert(false && "Default missing");
|
default: assert(false && "Default missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +226,7 @@ public:
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
||||||
case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break;
|
case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break;
|
||||||
|
case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
|
||||||
default: assert(false && "Default missing");
|
default: assert(false && "Default missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,6 +336,7 @@ private:
|
|||||||
int iConst; // used for ivec, scalar ints
|
int iConst; // used for ivec, scalar ints
|
||||||
bool bConst; // used for bvec, scalar bools
|
bool bConst; // used for bvec, scalar bools
|
||||||
float fConst; // used for vec, mat, scalar floats
|
float fConst; // used for vec, mat, scalar floats
|
||||||
|
double dConst; // used for dvec, dmat, scalar doubles
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
TBasicType type;
|
TBasicType type;
|
||||||
|
@ -235,6 +235,7 @@ public:
|
|||||||
switch (t) {
|
switch (t) {
|
||||||
case EbtVoid: return "void"; break;
|
case EbtVoid: return "void"; break;
|
||||||
case EbtFloat: return "float"; break;
|
case EbtFloat: return "float"; break;
|
||||||
|
case EbtDouble: return "double"; break;
|
||||||
case EbtInt: return "int"; break;
|
case EbtInt: return "int"; break;
|
||||||
case EbtBool: return "bool"; break;
|
case EbtBool: return "bool"; break;
|
||||||
case EbtSampler1D: return "sampler1D"; break;
|
case EbtSampler1D: return "sampler1D"; break;
|
||||||
|
@ -187,6 +187,7 @@ enum TOperator {
|
|||||||
EOpConstructInt,
|
EOpConstructInt,
|
||||||
EOpConstructBool,
|
EOpConstructBool,
|
||||||
EOpConstructFloat,
|
EOpConstructFloat,
|
||||||
|
EOpConstructDouble,
|
||||||
EOpConstructVec2,
|
EOpConstructVec2,
|
||||||
EOpConstructVec3,
|
EOpConstructVec3,
|
||||||
EOpConstructVec4,
|
EOpConstructVec4,
|
||||||
|
@ -246,6 +246,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
|
|||||||
case EOpConstructInt: newType = EbtInt; break;
|
case EOpConstructInt: newType = EbtInt; break;
|
||||||
case EOpConstructBool: newType = EbtBool; break;
|
case EOpConstructBool: newType = EbtBool; break;
|
||||||
case EOpConstructFloat: newType = EbtFloat; break;
|
case EOpConstructFloat: newType = EbtFloat; break;
|
||||||
|
case EOpConstructDouble: newType = EbtDouble; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ void TType::buildMangledName(TString& mangledName)
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EbtFloat: mangledName += 'f'; break;
|
case EbtFloat: mangledName += 'f'; break;
|
||||||
|
case EbtDouble: mangledName += 'd'; break;
|
||||||
case EbtInt: mangledName += 'i'; break;
|
case EbtInt: mangledName += 'i'; break;
|
||||||
case EbtBool: mangledName += 'b'; break;
|
case EbtBool: mangledName += 'b'; break;
|
||||||
case EbtSampler1D: mangledName += "s1"; break;
|
case EbtSampler1D: mangledName += "s1"; break;
|
||||||
|
@ -54,6 +54,8 @@ H [a-fA-F0-9]
|
|||||||
E [Ee][+-]?{D}+
|
E [Ee][+-]?{D}+
|
||||||
O [0-7]
|
O [0-7]
|
||||||
U [uU]
|
U [uU]
|
||||||
|
F [fF]
|
||||||
|
LF [lL][fF]
|
||||||
|
|
||||||
/* TODO: double literals, which will likely require pre-processor rework */
|
/* TODO: double literals, which will likely require pre-processor rework */
|
||||||
/* TODO: unsigned int literals, which will likely require pre-processor rework */
|
/* TODO: unsigned int literals, which will likely require pre-processor rework */
|
||||||
@ -329,9 +331,15 @@ TSourceLoc yylineno;
|
|||||||
0{D}+{U} { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;}
|
0{D}+{U} { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;}
|
||||||
{D}+{U} { pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(UINTCONSTANT); }
|
{D}+{U} { pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(UINTCONSTANT); }
|
||||||
|
|
||||||
{D}+{E} { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
{D}+{F} { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
||||||
{D}+"."{D}*({E})? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
{D}+{E}{F}? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
||||||
"."{D}+({E})? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
{D}+"."{D}*({E})?{F}? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
||||||
|
"."{D}+({E})?{F}? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }
|
||||||
|
|
||||||
|
{D}+{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return(DOUBLECONSTANT); }
|
||||||
|
{D}+{E}{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return(DOUBLECONSTANT); }
|
||||||
|
{D}+"."{D}*({E})?{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return(DOUBLECONSTANT); }
|
||||||
|
"."{D}+({E})?{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return(DOUBLECONSTANT); }
|
||||||
|
|
||||||
"/*" { int ret = PaParseComment(pyylval->lex.line, parseContext); if (!ret) return ret; }
|
"/*" { int ret = PaParseComment(pyylval->lex.line, parseContext); if (!ret) return ret; }
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ Jutta Degener, 1995
|
|||||||
float f;
|
float f;
|
||||||
int i;
|
int i;
|
||||||
bool b;
|
bool b;
|
||||||
|
double d;
|
||||||
};
|
};
|
||||||
TSymbol* symbol;
|
TSymbol* symbol;
|
||||||
} lex;
|
} lex;
|
||||||
@ -278,8 +279,8 @@ primary_expression
|
|||||||
}
|
}
|
||||||
| DOUBLECONSTANT {
|
| DOUBLECONSTANT {
|
||||||
constUnion *unionArray = new constUnion[1];
|
constUnion *unionArray = new constUnion[1];
|
||||||
unionArray->setFConst($1.f);
|
unionArray->setDConst($1.d);
|
||||||
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $1.line);
|
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtDouble, EvqConst), $1.line);
|
||||||
}
|
}
|
||||||
| BOOLCONSTANT {
|
| BOOLCONSTANT {
|
||||||
constUnion *unionArray = new constUnion[1];
|
constUnion *unionArray = new constUnion[1];
|
||||||
@ -1825,7 +1826,7 @@ type_specifier_nonarray
|
|||||||
| DOUBLE {
|
| DOUBLE {
|
||||||
TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
|
TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
|
||||||
// TODO: implement EbtDouble, check all float types
|
// TODO: implement EbtDouble, check all float types
|
||||||
$$.setBasic(EbtFloat, qual, $1.line);
|
$$.setBasic(EbtDouble, qual, $1.line);
|
||||||
}
|
}
|
||||||
| INT {
|
| INT {
|
||||||
// TODO: implement EbtUint, check all int types
|
// TODO: implement EbtUint, check all int types
|
||||||
|
@ -380,6 +380,15 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
|
|||||||
out.debug << buf << "\n";
|
out.debug << buf << "\n";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case EbtDouble:
|
||||||
|
{
|
||||||
|
const int maxSize = 300;
|
||||||
|
char buf[maxSize];
|
||||||
|
sprintf_s(buf, maxSize, "%f (%s)", node->getUnionArrayPointer()[i].getDConst(), "const double");
|
||||||
|
|
||||||
|
out.debug << buf << "\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
case EbtInt:
|
case EbtInt:
|
||||||
{
|
{
|
||||||
const int maxSize = 300;
|
const int maxSize = 300;
|
||||||
|
@ -127,6 +127,10 @@ struct CPPStruct_Rec {
|
|||||||
int PaArgc; // count of strings in the array
|
int PaArgc; // count of strings in the array
|
||||||
char** PaArgv; // our array of strings to parse
|
char** PaArgv; // our array of strings to parse
|
||||||
unsigned int tokensBeforeEOF : 1;
|
unsigned int tokensBeforeEOF : 1;
|
||||||
|
|
||||||
|
// Declared version of the shader
|
||||||
|
int version;
|
||||||
|
int profileAtom;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(__COMPILE_H)
|
#endif // !defined(__COMPILE_H)
|
||||||
|
@ -115,6 +115,9 @@ static int __LINE__Atom = 0;
|
|||||||
static int __FILE__Atom = 0;
|
static int __FILE__Atom = 0;
|
||||||
static int __VERSION__Atom = 0;
|
static int __VERSION__Atom = 0;
|
||||||
static int versionAtom = 0;
|
static int versionAtom = 0;
|
||||||
|
static int coreAtom = 0;
|
||||||
|
static int compatibilityAtom = 0;
|
||||||
|
static int esAtom = 0;
|
||||||
static int extensionAtom = 0;
|
static int extensionAtom = 0;
|
||||||
|
|
||||||
static Scope *macros = 0;
|
static Scope *macros = 0;
|
||||||
@ -149,6 +152,9 @@ int InitCPP(void)
|
|||||||
__FILE__Atom = LookUpAddString(atable, "__FILE__");
|
__FILE__Atom = LookUpAddString(atable, "__FILE__");
|
||||||
__VERSION__Atom = LookUpAddString(atable, "__VERSION__");
|
__VERSION__Atom = LookUpAddString(atable, "__VERSION__");
|
||||||
versionAtom = LookUpAddString(atable, "version");
|
versionAtom = LookUpAddString(atable, "version");
|
||||||
|
coreAtom = LookUpAddString(atable, "core");
|
||||||
|
compatibilityAtom = LookUpAddString(atable, "compatibility");
|
||||||
|
esAtom = LookUpAddString(atable, "es");
|
||||||
extensionAtom = LookUpAddString(atable, "extension");
|
extensionAtom = LookUpAddString(atable, "extension");
|
||||||
macros = NewScopeInPool(mem_CreatePool(0, 0));
|
macros = NewScopeInPool(mem_CreatePool(0, 0));
|
||||||
strcpy(buffer, "PROFILE_");
|
strcpy(buffer, "PROFILE_");
|
||||||
@ -660,8 +666,6 @@ static int CPPpragma(yystypepp * yylvalpp)
|
|||||||
return token;
|
return token;
|
||||||
} // CPPpragma
|
} // CPPpragma
|
||||||
|
|
||||||
#define GL2_VERSION_NUMBER 110
|
|
||||||
|
|
||||||
static int CPPversion(yystypepp * yylvalpp)
|
static int CPPversion(yystypepp * yylvalpp)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -680,10 +684,8 @@ static int CPPversion(yystypepp * yylvalpp)
|
|||||||
CPPErrorToInfoLog("#version");
|
CPPErrorToInfoLog("#version");
|
||||||
|
|
||||||
yylvalpp->sc_int=atoi(yylvalpp->symbol_name);
|
yylvalpp->sc_int=atoi(yylvalpp->symbol_name);
|
||||||
//SetVersionNumber(yylvalpp->sc_int);
|
|
||||||
|
|
||||||
if (yylvalpp->sc_int != GL2_VERSION_NUMBER)
|
cpp->version = yylvalpp->sc_int;
|
||||||
CPPShInfoLogMsg("Version number not supported by GL2");
|
|
||||||
|
|
||||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||||
|
|
||||||
@ -691,8 +693,20 @@ static int CPPversion(yystypepp * yylvalpp)
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
cpp->profileAtom = yylvalpp->sc_ident;
|
||||||
|
if (cpp->profileAtom != coreAtom &&
|
||||||
|
cpp->profileAtom != compatibilityAtom &&
|
||||||
|
cpp->profileAtom != esAtom)
|
||||||
|
CPPErrorToInfoLog("#version profile name");
|
||||||
|
|
||||||
|
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||||
|
|
||||||
|
if (token == '\n')
|
||||||
|
return token;
|
||||||
|
else
|
||||||
CPPErrorToInfoLog("#version");
|
CPPErrorToInfoLog("#version");
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
} // CPPversion
|
} // CPPversion
|
||||||
|
|
||||||
|
@ -132,6 +132,8 @@ int ResetPreprocessor(void)
|
|||||||
cpp->elsedepth[cpp->elsetracker]=0;
|
cpp->elsedepth[cpp->elsetracker]=0;
|
||||||
cpp->elsetracker=0;
|
cpp->elsetracker=0;
|
||||||
cpp->tokensBeforeEOF = 0;
|
cpp->tokensBeforeEOF = 0;
|
||||||
|
cpp->version = 110;
|
||||||
|
cpp->profileAtom = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int sc_int;
|
int sc_int;
|
||||||
float sc_fval;
|
float sc_fval;
|
||||||
|
double sc_dval;
|
||||||
int sc_ident;
|
int sc_ident;
|
||||||
char symbol_name[MAX_SYMBOL_NAME_LEN+1];
|
char symbol_name[MAX_SYMBOL_NAME_LEN+1];
|
||||||
} yystypepp;
|
} yystypepp;
|
||||||
|
@ -225,47 +225,9 @@ int ScanFromString(char *s)
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////// Floating point constants: /////////////////////////////////
|
/////////////////////////////////// Floating point constants: /////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/*
|
|
||||||
* lBuildFloatValue() - Quick and dirty conversion to floating point. Since all
|
|
||||||
* we need is single precision this should be quite precise.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static float lBuildFloatValue(const char *str, int len, int exp)
|
|
||||||
{
|
|
||||||
double val, expval, ten;
|
|
||||||
int ii, llen, absexp;
|
|
||||||
float rv;
|
|
||||||
|
|
||||||
val = 0.0;
|
|
||||||
llen = len;
|
|
||||||
for (ii = 0; ii < len; ii++)
|
|
||||||
val = val*10.0 + (str[ii] - '0');
|
|
||||||
if (exp != 0) {
|
|
||||||
absexp = exp > 0 ? exp : -exp;
|
|
||||||
expval = 1.0f;
|
|
||||||
ten = 10.0;
|
|
||||||
while (absexp) {
|
|
||||||
if (absexp & 1)
|
|
||||||
expval *= ten;
|
|
||||||
ten *= ten;
|
|
||||||
absexp >>= 1;
|
|
||||||
}
|
|
||||||
if (exp >= 0) {
|
|
||||||
val *= expval;
|
|
||||||
} else {
|
|
||||||
val /= expval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rv = (float)val;
|
|
||||||
if (isinff(rv)) {
|
|
||||||
CPPErrorToInfoLog(" ERROR___FP_CONST_OVERFLOW");
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
} // lBuildFloatValue
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* lFloatConst() - Scan a floating point constant. Assumes that the scanner
|
* lFloatConst() - Scan a single- or double-precision floating point constant. Assumes that the scanner
|
||||||
* has seen at least one digit, followed by either a decimal '.' or the
|
* has seen at least one digit, followed by either a decimal '.' or the
|
||||||
* letter 'e'.
|
* letter 'e'.
|
||||||
*/
|
*/
|
||||||
@ -274,7 +236,6 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
|||||||
{
|
{
|
||||||
int HasDecimal, declen, exp, ExpSign;
|
int HasDecimal, declen, exp, ExpSign;
|
||||||
int str_len;
|
int str_len;
|
||||||
float lval;
|
|
||||||
|
|
||||||
HasDecimal = 0;
|
HasDecimal = 0;
|
||||||
declen = 0;
|
declen = 0;
|
||||||
@ -303,6 +264,10 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
|||||||
// Exponent:
|
// Exponent:
|
||||||
|
|
||||||
if (ch == 'e' || ch == 'E') {
|
if (ch == 'e' || ch == 'E') {
|
||||||
|
if (len >= MAX_SYMBOL_NAME_LEN) {
|
||||||
|
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||||
|
len = 1,str_len=1;
|
||||||
|
} else {
|
||||||
ExpSign = 1;
|
ExpSign = 1;
|
||||||
str[len++]=ch;
|
str[len++]=ch;
|
||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
@ -316,28 +281,59 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
|||||||
}
|
}
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
while (ch >= '0' && ch <= '9') {
|
while (ch >= '0' && ch <= '9') {
|
||||||
|
if (len < MAX_SYMBOL_NAME_LEN) {
|
||||||
exp = exp*10 + ch - '0';
|
exp = exp*10 + ch - '0';
|
||||||
str[len++]=ch;
|
str[len++]=ch;
|
||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
} else {
|
||||||
|
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||||
|
len = 1,str_len=1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CPPErrorToInfoLog("ERROR___ERROR_IN_EXPONENT");
|
CPPErrorToInfoLog("ERROR___ERROR_IN_EXPONENT");
|
||||||
}
|
}
|
||||||
exp *= ExpSign;
|
exp *= ExpSign;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
lval = 0.0f;
|
yylvalpp->sc_fval = 0.0f;
|
||||||
|
yylvalpp->sc_dval = 0.0;
|
||||||
strcpy(str,"0.0");
|
strcpy(str,"0.0");
|
||||||
} else {
|
} else {
|
||||||
|
if (ch == 'l' || ch == 'L') {
|
||||||
|
int ch2 = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
if (ch2 != 'f' && ch2 != 'F') {
|
||||||
|
cpp->currentInput->ungetch(cpp->currentInput, ch2, yylvalpp);
|
||||||
|
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||||
|
} else {
|
||||||
|
if (len < MAX_SYMBOL_NAME_LEN-1) {
|
||||||
|
str[len++] = ch;
|
||||||
|
str[len++] = ch2;
|
||||||
|
} else {
|
||||||
|
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||||
|
len = 1,str_len=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ch == 'f' || ch == 'F') {
|
||||||
|
if (len < MAX_SYMBOL_NAME_LEN)
|
||||||
|
str[len++] = ch;
|
||||||
|
else {
|
||||||
|
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||||
|
len = 1,str_len=1;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||||
|
|
||||||
str[len]='\0';
|
str[len]='\0';
|
||||||
lval = lBuildFloatValue(str, str_len, exp - declen);
|
|
||||||
|
yylvalpp->sc_dval = strtod(str, 0);
|
||||||
|
yylvalpp->sc_fval = (float)yylvalpp->sc_dval;
|
||||||
}
|
}
|
||||||
// Suffix:
|
// Suffix:
|
||||||
|
|
||||||
yylvalpp->sc_fval = lval;
|
|
||||||
strcpy(yylvalpp->symbol_name,str);
|
strcpy(yylvalpp->symbol_name,str);
|
||||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
|
||||||
return CPP_FLOATCONSTANT;
|
return CPP_FLOATCONSTANT;
|
||||||
} // lFloatConst
|
} // lFloatConst
|
||||||
|
|
||||||
@ -454,7 +450,7 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||||||
}
|
}
|
||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
} while (ch >= '0' && ch <= '7');
|
} while (ch >= '0' && ch <= '7');
|
||||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E')
|
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L')
|
||||||
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
||||||
yylvalpp->symbol_name[len] = '\0';
|
yylvalpp->symbol_name[len] = '\0';
|
||||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||||
@ -476,7 +472,7 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
}
|
}
|
||||||
} while (ch >= '0' && ch <= '9');
|
} while (ch >= '0' && ch <= '9');
|
||||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E') {
|
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') {
|
||||||
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
||||||
} else {
|
} else {
|
||||||
yylvalpp->symbol_name[len] = '\0';
|
yylvalpp->symbol_name[len] = '\0';
|
||||||
|
@ -83,6 +83,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
typedef struct CPPStruct_Rec CPPStruct;
|
typedef struct CPPStruct_Rec CPPStruct;
|
||||||
|
|
||||||
|
// Multi-threading note: The existence of this global makes
|
||||||
|
// this preprocessing single-threaded only.
|
||||||
extern CPPStruct *cpp;
|
extern CPPStruct *cpp;
|
||||||
|
|
||||||
#undef CPPC_DEBUG_THE_COMPILER
|
#undef CPPC_DEBUG_THE_COMPILER
|
||||||
|
Loading…
x
Reference in New Issue
Block a user