Changed string offsets to size_t

git-svn-id: svn://10.0.0.236/branches/JS2_DIKDIK_BRANCH@98849 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
waldemar%netscape.com
2001-07-07 01:37:44 +00:00
parent d6a0e8b8e1
commit 1eb40cb8ee
10 changed files with 2528 additions and 2544 deletions

View File

@@ -32,60 +32,54 @@
*/
#include <cstdio>
#include "exception.h"
namespace JavaScript
{
namespace JS = JavaScript;
//
// Exceptions
//
static const char *const kindStrings[] = {
"Syntax error", // syntaxError
"Stack overflow", // stackOverflow
"Internal error", // diabetes
"Runtime error", // runtimeError
"Reference error", // referenceError
"Range error", // burnt the beans
"Type error", // Yype error
"Uncaught exception error", // uncaught exception error
"Semantic error", // semantic error
};
static const char *const kindStrings[] = {
"Syntax error", // syntaxError
"Stack overflow", // stackOverflow
"Internal error", // diabetes
"Runtime error", // runtimeError
"Reference error", // referenceError
"Range error", // burnt the beans
"Type error", // Yype error
"Uncaught exception error", // uncaught exception error
"Semantic error", // semantic error
};
// Return a null-terminated string describing the exception's kind.
const char *
Exception::kindString() const
{
return kindStrings[kind];
}
const char *JS::Exception::kindString() const
{
return kindStrings[kind];
}
// Return the full error message.
String
Exception::fullMessage() const
{
String m(widenCString("In "));
m += sourceFile;
if (lineNum) {
char b[32];
sprintf(b, ", line %d:\n", lineNum);
m += b;
m += sourceLine;
m += '\n';
String sourceLine2(sourceLine);
insertChars(sourceLine2, charNum, "[ERROR]");
m += sourceLine2;
m += '\n';
} else
m += ":\n";
m += kindString();
m += ": ";
m += message;
JS::String JS::Exception::fullMessage() const
{
String m(widenCString("In "));
m += sourceFile;
if (lineNum) {
char b[32];
sprintf(b, ", line %d:\n", lineNum);
m += b;
m += sourceLine;
m += '\n';
return m;
}
String sourceLine2(sourceLine);
insertChars(sourceLine2, charNum, "[ERROR]");
m += sourceLine2;
m += '\n';
} else
m += ":\n";
m += kindString();
m += ": ";
m += message;
m += '\n';
return m;
}

View File

@@ -38,13 +38,13 @@
namespace JavaScript
{
//
// Exceptions
//
// A JavaScript exception (other than out-of-memory, for which we use the
// standard C++ exception bad_alloc).
// A JavaScript exception (other than out-of-memory, for which we use the
// standard C++ exception bad_alloc).
struct Exception {
enum Kind {
syntaxError,
@@ -58,45 +58,38 @@ namespace JavaScript
semanticError
};
Kind kind; // The exception's kind
String message; // The detailed message
String sourceFile; // A description of the source code that caused the
// error
uint32 lineNum; // Number of line that caused the error
uint32 charNum; // Character offset within the line that caused the
// error
uint32 pos; // Offset within the input of the error
String sourceLine; // The text of the source line
Kind kind; // The exception's kind
String message; // The detailed message
String sourceFile; // A description of the source code that caused the error
uint32 lineNum; // Number of line that caused the error
size_t charNum; // Character offset within the line that caused the error
size_t pos; // Offset within the input of the error
String sourceLine; // The text of the source line
Exception (Kind kind, const char *message) :
Exception (Kind kind, const char *message):
kind(kind), message(widenCString(message)), lineNum(0), charNum(0) {}
Exception (Kind kind, const String &message) :
Exception (Kind kind, const String &message):
kind(kind), message(message), lineNum(0), charNum(0) {}
Exception(Kind kind, const String &message, const String &sourceFile,
uint32 lineNum, uint32 charNum, uint32 pos,
const String &sourceLine) :
kind(kind), message(message), sourceFile(sourceFile),
lineNum(lineNum), charNum(charNum), pos(pos), sourceLine(sourceLine)
{}
Exception(Kind kind, const String &message, const String &sourceFile, uint32 lineNum, size_t charNum,
size_t pos, const String &sourceLine):
kind(kind), message(message), sourceFile(sourceFile), lineNum(lineNum), charNum(charNum), pos(pos),
sourceLine(sourceLine) {}
Exception(Kind kind, const String &message, const String &sourceFile,
uint32 lineNum, uint32 charNum, uint32 pos,
const char16 *sourceLineBegin, const char16 *sourceLineEnd) :
kind(kind), message(message), sourceFile(sourceFile),
lineNum(lineNum), charNum(charNum), pos(pos),
sourceLine(sourceLineBegin, sourceLineEnd) {}
Exception(Kind kind, const String &message, const String &sourceFile, uint32 lineNum, size_t charNum,
size_t pos, const char16 *sourceLineBegin, const char16 *sourceLineEnd):
kind(kind), message(message), sourceFile(sourceFile), lineNum(lineNum), charNum(charNum), pos(pos),
sourceLine(sourceLineBegin, sourceLineEnd) {}
bool hasKind(Kind k) const {return kind == k;}
const char *kindString() const;
String fullMessage() const;
};
// Throw a stackOverflow exception if the execution stack has gotten too large.
// Throw a stackOverflow exception if the execution stack has gotten too large.
inline void checkStackSize() {}
}
#endif /* exception_h___ */

View File

@@ -333,7 +333,7 @@ bool JS::Lexer::lexNumeral()
reader.recordChar('0');
ch = getChar();
if ((ch&~0x20) == 'X') {
uint32 pos = reader.getPos();
size_t pos = reader.getPos();
char16 ch2 = getChar();
if (isASCIIHexDigit(ch2, digit)) {
reader.recordChar(ch);
@@ -354,7 +354,7 @@ bool JS::Lexer::lexNumeral()
ch = getChar();
}
if ((ch&~0x20) == 'E') {
uint32 pos = reader.getPos();
size_t pos = reader.getPos();
char16 ch2 = getChar();
char16 sign = 0;
if (ch2 == '+' || ch2 == '-') {

View File

@@ -71,7 +71,7 @@ namespace JavaScript
const Token &peek(bool preferRegExp);
void redesignate(bool preferRegExp);
void unget();
uint32 getPos() const;
size_t getPos() const;
private:
void syntaxError(const char *message, uint backUp = 1);
@@ -95,7 +95,7 @@ namespace JavaScript
#endif
// Return the position of the first character of the next token, which must have been peeked.
inline uint32 Lexer::getPos() const
inline size_t Lexer::getPos() const
{
ASSERT(nTokensFwd);
return nextToken->getPos();

View File

@@ -97,8 +97,8 @@ namespace JavaScript {
}
#endif
static StringExprNode *
LiteralString(uint32 pos, ExprNode::Kind kind, String &str) {
return new(getArena()) StringExprNode(pos,kind,str);
LiteralString(size_t pos, ExprNode::Kind kind, String &str) {
return new(getArena()) StringExprNode(pos, kind, str);
}
#if 0
static LiteralTypeNode

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -65,15 +65,14 @@ void JS::Reader::beginLine()
// Return the number of the line containing the given character position.
// The line starts should have been recorded by calling beginLine.
uint32 JS::Reader::posToLineNum(uint32 pos) const
uint32 JS::Reader::posToLineNum(size_t pos) const
{
ASSERT(pos <= getPos());
std::vector<const char16 *>::const_iterator i =
std::upper_bound(linePositions.begin(), linePositions.end(), begin + pos);
ASSERT(i != linePositions.begin());
return static_cast<uint32>(i-1 - linePositions.begin()) +
initialLineNum;
return static_cast<uint32>(i-1 - linePositions.begin()) + initialLineNum;
}
@@ -84,7 +83,7 @@ uint32 JS::Reader::posToLineNum(uint32 pos) const
// manually finds the line ending by searching for a line break; otherwise,
// getLine assumes that the line ends one character before the beginning
// of the next line.
uint32 JS::Reader::getLine(uint32 lineNum, const char16 *&lineBegin, const char16 *&lineEnd) const
size_t JS::Reader::getLine(uint32 lineNum, const char16 *&lineBegin, const char16 *&lineEnd) const
{
lineBegin = 0;
lineEnd = 0;
@@ -106,7 +105,7 @@ uint32 JS::Reader::getLine(uint32 lineNum, const char16 *&lineBegin, const char1
++e;
}
lineEnd = e;
return static_cast<uint32>(lineBegin - begin);
return toSize_t(lineBegin - begin);
}
@@ -156,12 +155,12 @@ JS::String &JS::Reader::endRecording()
// Report an error at the given character position in the source code.
void JS::Reader::error(Exception::Kind kind, const String &message, uint32 pos)
void JS::Reader::error(Exception::Kind kind, const String &message, size_t pos)
{
uint32 lineNum = posToLineNum(pos);
const char16 *lineBegin;
const char16 *lineEnd;
uint32 linePos = getLine(lineNum, lineBegin, lineEnd);
size_t linePos = getLine(lineNum, lineBegin, lineEnd);
ASSERT(lineBegin && lineEnd && linePos <= pos);
throw Exception(kind, message, sourceLocation, lineNum, pos - linePos, pos, lineBegin, lineEnd);

View File

@@ -69,9 +69,9 @@ namespace JavaScript {
char16 get() {ASSERT(p <= end);return *p++;}
char16 peek() {ASSERT(p <= end); return *p;}
void unget(uint32 n = 1) {ASSERT(p >= begin + n); p -= n;}
uint32 getPos() const {return static_cast<uint32>(p - begin);}
void setPos(uint32 pos) {ASSERT(pos <= getPos()); p = begin + pos;}
void unget(size_t n = 1) {ASSERT(p >= begin + n); p -= n;}
size_t getPos() const {return toSize_t(p - begin);}
void setPos(size_t pos) {ASSERT(pos <= getPos()); p = begin + pos;}
bool eof() const {ASSERT(p <= end); return p == end;}
bool peekEof(char16 ch) const {
@@ -85,13 +85,13 @@ namespace JavaScript {
ASSERT(p[-1] == ch); return !ch && p == end+1;
}
void beginLine();
uint32 posToLineNum(uint32 pos) const;
uint32 getLine(uint32 lineNum, const char16 *&lineBegin, const char16 *&lineEnd) const;
uint32 posToLineNum(size_t pos) const;
size_t getLine(uint32 lineNum, const char16 *&lineBegin, const char16 *&lineEnd) const;
void beginRecording(String &recordString);
void recordChar(char16 ch);
String &endRecording();
void error(Exception::Kind kind, const String &message, uint32 pos);
void error(Exception::Kind kind, const String &message, size_t pos);
};

View File

@@ -229,7 +229,7 @@ namespace JavaScript
#endif
Kind kind; // The token's kind
bool lineBreak; // True if line break precedes this token
uint32 pos; // Source position of this token
size_t pos; // Source position of this token
const StringAtom *id; // The token's characters; non-nil for identifiers, keywords, and regular expressions only
String chars; // The token's characters; valid for strings, units, numbers, and regular expression flags only
float64 value; // The token's value (numbers only)
@@ -247,7 +247,7 @@ namespace JavaScript
bool hasIdentifierKind() const {ASSERT(nonreservedEnd == identifier && kindsEnd == identifier+1); return kind >= nonreservedBegin;}
bool getFlag(Flag f) const {ASSERT(valid); return (kindFlags[kind] & 1<<f) != 0;}
bool getLineBreak() const {ASSERT(valid); return lineBreak;}
uint32 getPos() const {ASSERT(valid); return pos;}
size_t getPos() const {ASSERT(valid); return pos;}
const StringAtom &getIdentifier() const {ASSERT(valid && id); return *id;}
const String &getChars() const {ASSERT(valid && kind >= kindsWithCharsBegin && kind < kindsWithCharsEnd); return chars;}
float64 getValue() const {ASSERT(valid && kind == number); return value;}