gecko-dev/dom/tools/IdlScanner.h

222 lines
5.2 KiB
C
Raw Normal View History

1998-05-12 20:30:45 +00:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1998-05-12 20:30:45 +00:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1998-05-12 20:30:45 +00:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-05-12 20:30:45 +00:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-05-12 20:30:45 +00:00
*/
#ifndef _IdlScanner_h__
#define _IdlScanner_h__
#include <string.h>
#ifdef XP_MAC
#include <fstream.h> // required for namespace resolution
#else
1998-05-12 20:30:45 +00:00
class ifstream;
#endif
1998-05-12 20:30:45 +00:00
#define MAX_ID_LENGHT 256
enum EIDLTokenType {
1998-05-12 20:30:45 +00:00
EOF_TOKEN = -1,
ERROR_TOKEN = 0,
COMMENT_TOKEN = 1,
INTERFACE_TOKEN,
TYPEDEF_TOKEN,
STRUCT_TOKEN,
ENUM_TOKEN,
UNION_TOKEN,
CONST_TOKEN,
EXCEPTION_TOKEN,
READONLY_TOKEN,
OPTIONAL_TOKEN,
1999-03-10 19:55:00 +00:00
XPIDL_TOKEN,
1999-03-28 22:19:42 +00:00
FUNC_TOKEN,
ELLIPSIS_TOKEN,
IID_TOKEN,
1998-05-12 20:30:45 +00:00
ATTRIBUTE_TOKEN,
IDENTIFIER_TOKEN,
BOOLEAN_TOKEN,
FLOAT_TOKEN,
DOUBLE_TOKEN,
LONG_TOKEN,
SHORT_TOKEN,
ULONG_TOKEN,
USHORT_TOKEN,
CHAR_TOKEN,
INT_TOKEN,
UINT_TOKEN,
STRING_TOKEN,
JSVAL_TOKEN,
1998-05-12 20:30:45 +00:00
INPUT_PARAM_TOKEN,
OUTPUT_PARAM_TOKEN,
INOUT_PARAM_TOKEN,
1998-05-15 18:49:17 +00:00
RAISES_TOKEN,
1998-05-12 20:30:45 +00:00
INHERITANCE_SPEC_TOKEN, // ':'
SEPARATOR_TOKEN, // ','
BEGIN_BLOCK_TOKEN, // '{'
END_BLOCK_TOKEN, // '}'
TERMINATOR_TOKEN, // ';'
ASSIGNEMENT_TOKEN, // '='
FUNC_PARAMS_SPEC_BEGIN_TOKEN, // '('
FUNC_PARAMS_SPEC_END_TOKEN, // ')'
VOID_TOKEN,
NOSCRIPT_TOKEN,
UNKNOWN_TOKEN,
1998-05-12 20:30:45 +00:00
// constant values
INTEGER_CONSTANT = 1000,
STRING_CONSTANT
};
struct Token {
int id;
char *stringID;
union {
// long is the only one used so far
unsigned long vLong;
// still unused...
char vChar;
char *vString;
double vDouble;
} value;
Token()
{
id = 0;
stringID = (char*)0;
memset(&value, 0, sizeof(value));
}
~Token()
{
if (STRING_CONSTANT == id) {
delete[] value.vString;
}
delete[] stringID;
}
void SetToken(int aID, char *aString = 0)
{
if (STRING_CONSTANT == id) {
delete[] value.vString;
}
id = aID;
if (stringID) {
delete[] stringID;
}
if (aString) {
stringID = new char[strlen(aString) + 1];
memcpy(stringID, aString, strlen(aString) + 1);
}
else {
stringID = (char*)0;
}
memset(&value, 0, sizeof(value));
}
void SetTokenValue(int aID, long aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vLong = (unsigned long)aValue;
}
void SetTokenValue(int aID, char aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vChar = aValue;
}
void SetTokenValue(int aID, char *aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vString = aValue;
}
void SetTokenValue(int aID, double aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vDouble = aValue;
}
};
class IdlScanner {
private:
ifstream *mInputFile;
char *mFileName;
Token *mToken1;
Token *mToken2;
Token *mCurrentToken;
long mLineNumber;
int mTokenPeeked;
char mTokenName[MAX_ID_LENGHT];
public:
IdlScanner();
~IdlScanner();
char* GetFileName();
void SetFileName(char *aFileName);
long GetLineNumber();
int Open(char *aFileName);
int CanReadMoreData();
Token* PeekToken();
Token* NextToken();
protected:
void SetCurrentToken();
int EatWhiteSpace();
void AKeywords(char *aCurrentPos, Token *aToken);
void BKeywords(char *aCurrentPos, Token *aToken);
void CKeywords(char *aCurrentPos, Token *aToken);
void DKeywords(char *aCurrentPos, Token *aToken);
void EKeywords(char *aCurrentPos, Token *aToken);
void FKeywords(char *aCurrentPos, Token *aToken);
void IKeywords(char *aCurrentPos, Token *aToken);
void JKeywords(char *aCurrentPos, Token *aToken);
1998-05-12 20:30:45 +00:00
void LKeywords(char *aCurrentPos, Token *aToken);
void NKeywords(char *aCurrentPos, Token *aToken);
1998-05-12 20:30:45 +00:00
void OKeywords(char *aCurrentPos, Token *aToken);
void RKeywords(char *aCurrentPos, Token *aToken);
void SKeywords(char *aCurrentPos, Token *aToken);
void TKeywords(char *aCurrentPos, Token *aToken);
void UKeywords(char *aCurrentPos, Token *aToken);
void VKeywords(char *aCurrentPos, Token *aToken);
1998-05-12 20:30:45 +00:00
void WKeywords(char *aCurrentPos, Token *aToken);
1999-03-10 19:55:00 +00:00
void XKeywords(char *aCurrentPos, Token *aToken);
1998-05-12 20:30:45 +00:00
void Identifier(char *aCurrentPos, Token *aToken);
void Number(int aStartChar, Token *aToken);
void String(int aStartChar, Token *aToken);
void Char(int aStartChar, Token *aToken);
void Comment(char *aCurrentPos, Token *aToken);
void KeywordMismatch(int aChar, char *aCurrentPos, Token *aToken);
};
#endif // _IdlScanner_h__