Browse Source

Properly report filename and line number when parsing error happens in an include file

BearishSun 10 years ago
parent
commit
6236ab2478

+ 0 - 2
BansheeEngine/Include/BsImageSprite.h

@@ -9,7 +9,6 @@
 
 namespace BansheeEngine
 {
-	/** @cond INTERNAL */
 	/** @addtogroup 2D
 	 *  @{
 	 */
@@ -62,5 +61,4 @@ namespace BansheeEngine
 	};
 
 	/** @} */
-	/** @endcond */
 }

+ 34 - 31
BansheeSL/BsLexerFX.c

@@ -915,7 +915,7 @@ static yyconst flex_int32_t yy_rule_can_match_eol[194] =
 #line 2 "BsLexerFX.l"
 #include "BsParserFX.h"
 
-#define YY_USER_ACTION yylloc->first_column = yycolumn + 1; yylloc->first_line = yylineno + 1; yycolumn += (int)yyleng;
+#define YY_USER_ACTION yylloc->first_column = yycolumn + 1; yylloc->first_line = yylineno + 1; yycolumn += (int)yyleng; yylloc->filename = getCurrentFilename(yyextra);
 #define YY_USER_INIT yylineno = 0; yycolumn = 0;
 #define YY_NO_UNISTD_H 1
 /* Start conditions */
@@ -2120,12 +2120,15 @@ YY_RULE_SETUP
 	yy_switch_to_buffer(currentBuffer,yyscanner);
 	yypush_buffer_state(newBuffer,yyscanner);
 
+	yylineno = 0; 
+	yycolumn = 0;
+
 	BEGIN(INITIAL);
 	}
 	YY_BREAK
 case 167:
 YY_RULE_SETUP
-#line 250 "BsLexerFX.l"
+#line 253 "BsLexerFX.l"
 { return yytext[0]; }
 	YY_BREAK
 case YY_STATE_EOF(INITIAL):
@@ -2134,7 +2137,7 @@ case YY_STATE_EOF(CODEBLOCK_HEADER):
 case YY_STATE_EOF(CODEBLOCK_EQUALS):
 case YY_STATE_EOF(CODEBLOCK):
 case YY_STATE_EOF(CODEBLOCK_END):
-#line 252 "BsLexerFX.l"
+#line 255 "BsLexerFX.l"
 {
 	if(!yyextra->includeStack)
 		yyterminate();
@@ -2146,37 +2149,37 @@ case YY_STATE_EOF(CODEBLOCK_END):
 /* Code blocks */
 case 168:
 YY_RULE_SETUP
-#line 261 "BsLexerFX.l"
+#line 264 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_VERTEX; }
 	YY_BREAK
 case 169:
 YY_RULE_SETUP
-#line 262 "BsLexerFX.l"
+#line 265 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_FRAGMENT; }
 	YY_BREAK
 case 170:
 YY_RULE_SETUP
-#line 263 "BsLexerFX.l"
+#line 266 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_GEOMETRY; }
 	YY_BREAK
 case 171:
 YY_RULE_SETUP
-#line 264 "BsLexerFX.l"
+#line 267 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_HULL; }
 	YY_BREAK
 case 172:
 YY_RULE_SETUP
-#line 265 "BsLexerFX.l"
+#line 268 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_DOMAIN; }
 	YY_BREAK
 case 173:
 YY_RULE_SETUP
-#line 266 "BsLexerFX.l"
+#line 269 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_COMPUTE; }
 	YY_BREAK
 case 174:
 YY_RULE_SETUP
-#line 267 "BsLexerFX.l"
+#line 270 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_HEADER); return TOKEN_COMMON; }
 	YY_BREAK
 /* Track when the code block begins, insert all code block characters into our own buffer, record a sequential index */
@@ -2184,44 +2187,44 @@ YY_RULE_SETUP
 /* And finally output a sequential code block index to the parser (it shouldn't be aware of anything else in the block). */
 case 175:
 YY_RULE_SETUP
-#line 272 "BsLexerFX.l"
+#line 275 "BsLexerFX.l"
 { BEGIN(CODEBLOCK_EQUALS); return yytext[0]; }
 	YY_BREAK
 case 176:
 /* rule 176 can match eol */
 YY_RULE_SETUP
-#line 273 "BsLexerFX.l"
+#line 276 "BsLexerFX.l"
 { /* Skip blank */ }
 	YY_BREAK
 case 177:
 YY_RULE_SETUP
-#line 274 "BsLexerFX.l"
+#line 277 "BsLexerFX.l"
 { return yytext[0]; }
 	YY_BREAK
 case 178:
 YY_RULE_SETUP
-#line 276 "BsLexerFX.l"
+#line 279 "BsLexerFX.l"
 { BEGIN(CODEBLOCK); beginCodeBlock(yyextra); yyextra->numOpenBrackets = 1; return yytext[0]; }
 	YY_BREAK
 case 179:
 /* rule 179 can match eol */
 YY_RULE_SETUP
-#line 277 "BsLexerFX.l"
+#line 280 "BsLexerFX.l"
 { /* Skip blank */ }
 	YY_BREAK
 case 180:
 YY_RULE_SETUP
-#line 278 "BsLexerFX.l"
+#line 281 "BsLexerFX.l"
 { return yytext[0]; }
 	YY_BREAK
 case 181:
 YY_RULE_SETUP
-#line 280 "BsLexerFX.l"
+#line 283 "BsLexerFX.l"
 { yyextra->numOpenBrackets++; appendCodeBlock(yyextra, yytext[0]); }
 	YY_BREAK
 case 182:
 YY_RULE_SETUP
-#line 281 "BsLexerFX.l"
+#line 284 "BsLexerFX.l"
 { 
 	yyextra->numOpenBrackets--; 
 
@@ -2237,7 +2240,7 @@ YY_RULE_SETUP
 case 183:
 /* rule 183 can match eol */
 YY_RULE_SETUP
-#line 292 "BsLexerFX.l"
+#line 295 "BsLexerFX.l"
 { appendCodeBlock(yyextra, yytext[0]); }
 	YY_BREAK
 /* Logic for manually inserting "Index = codeBlockIndex;". We insert arbitrary numbers which allows us to sequentially */
@@ -2245,57 +2248,57 @@ YY_RULE_SETUP
 /* (since the starting value was also a single character "{"). */
 case 184:
 YY_RULE_SETUP
-#line 297 "BsLexerFX.l"
+#line 300 "BsLexerFX.l"
 { unput('1'); return TOKEN_INDEX; }
 	YY_BREAK
 case 185:
 YY_RULE_SETUP
-#line 298 "BsLexerFX.l"
+#line 301 "BsLexerFX.l"
 { unput('2'); return '='; }
 	YY_BREAK
 case 186:
 YY_RULE_SETUP
-#line 299 "BsLexerFX.l"
+#line 302 "BsLexerFX.l"
 { yylval->intValue = getCodeBlockIndex(yyextra); unput('3'); return TOKEN_INTEGER; }
 	YY_BREAK
 case 187:
 YY_RULE_SETUP
-#line 300 "BsLexerFX.l"
+#line 303 "BsLexerFX.l"
 { unput('4'); return ';'; }
 	YY_BREAK
 case 188:
 YY_RULE_SETUP
-#line 301 "BsLexerFX.l"
+#line 304 "BsLexerFX.l"
 { BEGIN(INITIAL); return '}'; }
 	YY_BREAK
 case 189:
 /* rule 189 can match eol */
 YY_RULE_SETUP
-#line 302 "BsLexerFX.l"
+#line 305 "BsLexerFX.l"
 { /* Never reached */ }
 	YY_BREAK
 /* Catch all rules */
 case 190:
 YY_RULE_SETUP
-#line 305 "BsLexerFX.l"
+#line 308 "BsLexerFX.l"
 { }
 	YY_BREAK
 case 191:
 YY_RULE_SETUP
-#line 306 "BsLexerFX.l"
+#line 309 "BsLexerFX.l"
 { yylval->strValue = mmalloc_strdup(yyextra->memContext, yytext); return TOKEN_IDENTIFIER; }
 	YY_BREAK
 case 192:
 YY_RULE_SETUP
-#line 307 "BsLexerFX.l"
+#line 310 "BsLexerFX.l"
 { return yytext[0]; }
 	YY_BREAK
 case 193:
 YY_RULE_SETUP
-#line 309 "BsLexerFX.l"
+#line 312 "BsLexerFX.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 2299 "BsLexerFX.c"
+#line 2302 "BsLexerFX.c"
 
 	case YY_END_OF_BUFFER:
 		{
@@ -3481,6 +3484,6 @@ void yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 308 "BsLexerFX.l"
+#line 311 "BsLexerFX.l"
 
 

+ 1 - 1
BansheeSL/BsLexerFX.h

@@ -342,7 +342,7 @@ extern int yylex \
 #undef YY_DECL
 #endif
 
-#line 308 "BsLexerFX.l"
+#line 311 "BsLexerFX.l"
 
 
 #line 349 "BsLexerFX.h"

+ 4 - 1
BansheeSL/BsLexerFX.l

@@ -1,7 +1,7 @@
 %{
 #include "BsParserFX.h"
 
-#define YY_USER_ACTION yylloc->first_column = yycolumn + 1; yylloc->first_line = yylineno + 1; yycolumn += (int)yyleng;
+#define YY_USER_ACTION yylloc->first_column = yycolumn + 1; yylloc->first_line = yylineno + 1; yycolumn += (int)yyleng; yylloc->filename = getCurrentFilename(yyextra);
 #define YY_USER_INIT yylineno = 0; yycolumn = 0;
 %}
  
@@ -245,6 +245,9 @@ DYNAMIC			{ yylval->intValue = BUV_Dynamic; return TOKEN_BUFFERUSAGE; }
 	yy_switch_to_buffer(currentBuffer, yyscanner);
 	yypush_buffer_state(newBuffer, yyscanner);
 
+	yylineno = 0; 
+	yycolumn = 0;
+
 	BEGIN(INITIAL);
 	}
 <INCLUDE>.				{ return yytext[0]; }

File diff suppressed because it is too large
+ 153 - 153
BansheeSL/BsParserFX.c


+ 30 - 3
BansheeSL/BsParserFX.h

@@ -52,6 +52,33 @@ extern int yydebug;
 	typedef void* yyscan_t;
 #endif
 
+typedef struct YYLTYPE {
+	int first_line;
+	int first_column;
+	int last_line;
+	int last_column;
+	char *filename;
+} YYLTYPE;
+#define YYLTYPE_IS_DECLARED 1
+
+#define YYLLOC_DEFAULT(Current, Rhs, N)																\
+	do																								\
+		if (N)																						\
+		{																							\
+			(Current).first_line = YYRHSLOC (Rhs, 1).first_line;									\
+			(Current).first_column = YYRHSLOC (Rhs, 1).first_column;								\
+			(Current).last_line = YYRHSLOC (Rhs, N).last_line;										\
+			(Current).last_column = YYRHSLOC (Rhs, N).last_column;									\
+			(Current).filename = YYRHSLOC (Rhs, 1).filename;										\
+		}																							\
+		else																						\
+		{																							\
+			(Current).first_line = (Current).last_line = YYRHSLOC (Rhs, 0).last_line;				\
+			(Current).first_column = (Current).last_column = YYRHSLOC (Rhs, 0).last_column;			\
+			(Current).filename = NULL;																\
+		}																							\
+	while (0)
+
 #define ADD_PARAMETER(OUTPUT, TYPE, NAME)															\
 			OUTPUT = nodeCreate(parse_state->memContext, NT_Parameter);								\
 			nodePush(parse_state, OUTPUT);															\
@@ -70,7 +97,7 @@ extern int yydebug;
 
 
 /* Line 2579 of glr.c  */
-#line 74 "BsParserFX.h"
+#line 101 "BsParserFX.h"
 
 /* Tokens.  */
 #ifndef YYTOKENTYPE
@@ -198,7 +225,7 @@ extern int yydebug;
 typedef union YYSTYPE
 {
 /* Line 2579 of glr.c  */
-#line 46 "BsParserFX.y"
+#line 73 "BsParserFX.y"
 
 	int intValue;
 	float floatValue;
@@ -210,7 +237,7 @@ typedef union YYSTYPE
 
 
 /* Line 2579 of glr.c  */
-#line 214 "BsParserFX.h"
+#line 241 "BsParserFX.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */

+ 28 - 0
BansheeSL/BsParserFX.y

@@ -16,6 +16,33 @@ void yyerror(YYLTYPE *locp, ParseState* parse_state, yyscan_t scanner, const cha
 	typedef void* yyscan_t;
 #endif
 
+typedef struct YYLTYPE {
+	int first_line;
+	int first_column;
+	int last_line;
+	int last_column;
+	char *filename;
+} YYLTYPE;
+#define YYLTYPE_IS_DECLARED 1
+
+#define YYLLOC_DEFAULT(Current, Rhs, N)																\
+	do																								\
+		if (N)																						\
+		{																							\
+			(Current).first_line = YYRHSLOC (Rhs, 1).first_line;									\
+			(Current).first_column = YYRHSLOC (Rhs, 1).first_column;								\
+			(Current).last_line = YYRHSLOC (Rhs, N).last_line;										\
+			(Current).last_column = YYRHSLOC (Rhs, N).last_column;									\
+			(Current).filename = YYRHSLOC (Rhs, 1).filename;										\
+		}																							\
+		else																						\
+		{																							\
+			(Current).first_line = (Current).last_line = YYRHSLOC (Rhs, 0).last_line;				\
+			(Current).first_column = (Current).last_column = YYRHSLOC (Rhs, 0).last_column;			\
+			(Current).filename = NULL;																\
+		}																							\
+	while (0)
+
 #define ADD_PARAMETER(OUTPUT, TYPE, NAME)															\
 			OUTPUT = nodeCreate(parse_state->memContext, NT_Parameter);								\
 			nodePush(parse_state, OUTPUT);															\
@@ -947,4 +974,5 @@ void yyerror(YYLTYPE *locp, ParseState* parse_state, yyscan_t scanner, const cha
 	parse_state->errorLine = locp->first_line;
 	parse_state->errorColumn = locp->first_column;
 	parse_state->errorMessage = mmalloc_strdup(parse_state->memContext, msg);
+	parse_state->errorFile = locp->filename;
 }

+ 3 - 0
BansheeSL/Include/BsASTFX.h

@@ -230,6 +230,7 @@ struct tagParseState
 	int errorLine;
 	int errorColumn;
 	const char* errorMessage;
+	char* errorFile;
 
 	NodeLink* nodeStack;
 	IncludeLink* includeStack;
@@ -294,6 +295,8 @@ void beginCodeBlock(ParseState* parseState);
 void appendCodeBlock(ParseState* parseState, char value);
 int getCodeBlockIndex(ParseState* parseState);
 
+char* getCurrentFilename(ParseState* parseState);
+
 ParseState* parseStateCreate();
 void parseStateDelete(ParseState* parseState);
 

+ 1 - 0
BansheeSL/Include/BsSLFXCompiler.h

@@ -22,6 +22,7 @@ namespace BansheeEngine
 		String errorMessage; /**< Error message if compilation failed. */
 		int errorLine = 0; /**< Line of the error if one occurred. */
 		int errorColumn = 0; /**< Column of the error if one occurred. */
+		String errorFile; /**< File in which the error occurred. Empty if root file. */
 	};
 
 	/**	Transforms a source file written in BSL FX syntax into a Shader object. */

+ 10 - 1
BansheeSL/Source/BsASTFX.c

@@ -201,7 +201,7 @@ void beginCodeBlock(ParseState* parseState)
 	CodeString* codeString = (CodeString*)mmalloc(parseState->memContext, sizeof(CodeString));
 	codeString->index = parseState->numCodeStrings;
 	codeString->size = 0;
-	codeString->capacity = 128;
+	codeString->capacity = 4096;
 	codeString->code = mmalloc(parseState->memContext, codeString->capacity);
 	codeString->next = parseState->codeStrings;
 
@@ -232,6 +232,14 @@ int getCodeBlockIndex(ParseState* parseState)
 	return parseState->codeStrings->index;
 }
 
+char* getCurrentFilename(ParseState* parseState)
+{
+	if (!parseState->includeStack)
+		return NULL;
+
+	return parseState->includeStack->data->filename;
+}
+
 ParseState* parseStateCreate()
 {
 	ParseState* parseState = (ParseState*)malloc(sizeof(ParseState));
@@ -249,6 +257,7 @@ ParseState* parseStateCreate()
 	parseState->errorLine = 0;
 	parseState->errorColumn = 0;
 	parseState->errorMessage = 0;
+	parseState->errorFile = 0;
 
 	nodePush(parseState, parseState->rootNode);
 

+ 1 - 0
BansheeSL/Source/BsIncludeHandler.cpp

@@ -71,6 +71,7 @@ char* includePush(ParseState* state, const char* filename, int line, int column,
 	state->errorLine = line;
 	state->errorColumn = column;
 	state->errorMessage = message;
+	state->errorFile = getCurrentFilename(state);
 
 	mmfree(filenameNoQuote);
 	return nullptr;

+ 3 - 0
BansheeSL/Source/BsSLFXCompiler.cpp

@@ -81,6 +81,9 @@ namespace BansheeEngine
 			output.errorLine = parseState->errorLine;
 			output.errorColumn = parseState->errorColumn;
 
+			if(parseState->errorFile != nullptr)
+				output.errorFile = parseState->errorFile;
+
 			parseStateDelete(parseState);
 		}
 		else

+ 7 - 1
BansheeSL/Source/BsSLImporter.cpp

@@ -42,7 +42,13 @@ namespace BansheeEngine
 			result.shader->setName(filePath.getWFilename(false));
 		else
 		{
-			LOGERR("Error while parsing shader FX code \"" + filePath.toString() + "\":\n" + result.errorMessage + ". Location: " +
+			String file;
+			if (result.errorFile.empty())
+				file = filePath.toString();
+			else
+				file = result.errorFile;
+
+			LOGERR("Error while parsing shader FX code \"" + file + "\":\n" + result.errorMessage + ". Location: " +
 				toString(result.errorLine) + " (" + toString(result.errorColumn) + ")");
 		}
 

Some files were not shown because too many files changed in this diff