PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lscript/lscript_compile/lscript_error.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 103 lines | 66 code | 12 blank | 25 comment | 1 complexity | e2adc0ff66ed0b39e82eee8325a4f773 MD5 | raw file
  1/** 
  2 * @file lscript_error.cpp
  3 * @brief error reporting class and strings
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "lscript_error.h"
 30
 31S32 gColumn = 0;
 32S32 gLine = 0;
 33S32 gInternalColumn = 0;
 34S32 gInternalLine = 0;
 35
 36LLScriptGenerateErrorText gErrorToText;
 37
 38void LLScriptFilePosition::fdotabs(LLFILE *fp, S32 tabs, S32 tabsize)
 39{
 40	S32 i;
 41	for (i = 0; i < tabs * tabsize; i++)
 42	{
 43		fprintf(fp, " ");
 44	}
 45}
 46
 47const char* gWarningText[LSWARN_EOF] = 	 	/*Flawfinder: ignore*/
 48{
 49	"INVALID",
 50	"Dead code found beyond return statement"
 51};
 52
 53const char* gErrorText[LSERROR_EOF] = 	/*Flawfinder: ignore*/
 54{
 55	"INVALID",
 56	"Syntax error",
 57	"Not all code paths return a value",
 58	"Function returns a value but return statement doesn't",
 59	"Return statement type doesn't match function return type",
 60	"Global functions can't change state",
 61	"Name previously declared within scope",
 62	"Name not defined within scope",
 63	"Type mismatch",
 64	"Expression must act on LValue",
 65	"Byte code assembly failed -- out of memory",
 66	"Function call mismatches type or number of arguments",
 67	"Use of vector or quaternion method on incorrect type",
 68	"Lists can't be included in lists",
 69	"Unitialized variables can't be included in lists",
 70	"Declaration requires a new scope -- use { and }",
 71	"CIL assembler failed",
 72	"Bytecode transformer failed",
 73	"Bytecode verification failed"
 74};
 75
 76void LLScriptGenerateErrorText::writeWarning(LLFILE *fp, LLScriptFilePosition *pos, LSCRIPTWarnings warning)
 77{
 78	fprintf(fp, "(%d, %d) : WARNING : %s\n", pos->mLineNumber, pos->mColumnNumber, gWarningText[warning]);
 79	mTotalWarnings++;
 80}
 81
 82void LLScriptGenerateErrorText::writeWarning(LLFILE *fp, S32 line, S32 col, LSCRIPTWarnings warning)
 83{
 84	fprintf(fp, "(%d, %d) : WARNING : %s\n", line, col, gWarningText[warning]);
 85	mTotalWarnings++;
 86}
 87
 88void LLScriptGenerateErrorText::writeError(LLFILE *fp, LLScriptFilePosition *pos, LSCRIPTErrors error)
 89{
 90	fprintf(fp, "(%d, %d) : ERROR : %s\n", pos->mLineNumber, pos->mColumnNumber, gErrorText[error]);
 91	mTotalErrors++;
 92}
 93
 94void LLScriptGenerateErrorText::writeError(LLFILE *fp, S32 line, S32 col, LSCRIPTErrors error)
 95{
 96	fprintf(fp, "(%d, %d) : ERROR : %s\n", line, col, gErrorText[error]);
 97	mTotalErrors++;
 98}
 99
100std::string getLScriptErrorString(LSCRIPTErrors error)
101{
102	return gErrorText[error];
103}