summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2016-01-28 00:25:44 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-01-28 00:25:44 +0100
commita7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90 (patch)
treec76678dd93865f5050155dae02963d3d4ad66c05
parentMerge "Change BCB to perform synchronous writes." am: 5797bf9c90 (diff)
parentMerge "edify: accept long string literal." (diff)
downloadandroid_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.tar
android_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.tar.gz
android_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.tar.bz2
android_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.tar.lz
android_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.tar.xz
android_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.tar.zst
android_bootable_recovery-a7e7cef9490c79d9d8d8ea3ffeb79328fc34ad90.zip
-rw-r--r--edify/lexer.ll24
-rw-r--r--edify/main.cpp5
2 files changed, 16 insertions, 13 deletions
diff --git a/edify/lexer.ll b/edify/lexer.ll
index fb2933bee..b764d1699 100644
--- a/edify/lexer.ll
+++ b/edify/lexer.ll
@@ -16,6 +16,7 @@
*/
#include <string.h>
+#include <string>
#include "expr.h"
#include "yydefs.h"
@@ -25,9 +26,7 @@ int gLine = 1;
int gColumn = 1;
int gPos = 0;
-// TODO: enforce MAX_STRING_LEN during lexing
-char string_buffer[MAX_STRING_LEN];
-char* string_pos;
+std::string string_buffer;
#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \
gColumn+=yyleng; gPos+=yyleng;} while(0)
@@ -43,7 +42,7 @@ char* string_pos;
\" {
BEGIN(STR);
- string_pos = string_buffer;
+ string_buffer.clear();
yylloc.start = gPos;
++gColumn;
++gPos;
@@ -54,36 +53,35 @@ char* string_pos;
++gColumn;
++gPos;
BEGIN(INITIAL);
- *string_pos = '\0';
- yylval.str = strdup(string_buffer);
+ yylval.str = strdup(string_buffer.c_str());
yylloc.end = gPos;
return STRING;
}
- \\n { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\n'; }
- \\t { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\t'; }
- \\\" { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\"'; }
- \\\\ { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\\'; }
+ \\n { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\n'); }
+ \\t { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\t'); }
+ \\\" { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\"'); }
+ \\\\ { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\\'); }
\\x[0-9a-fA-F]{2} {
gColumn += yyleng;
gPos += yyleng;
int val;
sscanf(yytext+2, "%x", &val);
- *string_pos++ = val;
+ string_buffer.push_back(static_cast<char>(val));
}
\n {
++gLine;
++gPos;
gColumn = 1;
- *string_pos++ = yytext[0];
+ string_buffer.push_back(yytext[0]);
}
. {
++gColumn;
++gPos;
- *string_pos++ = yytext[0];
+ string_buffer.push_back(yytext[0]);
}
}
diff --git a/edify/main.cpp b/edify/main.cpp
index b1baa0b13..6007a3d58 100644
--- a/edify/main.cpp
+++ b/edify/main.cpp
@@ -18,6 +18,8 @@
#include <stdlib.h>
#include <string.h>
+#include <string>
+
#include "expr.h"
#include "parser.h"
@@ -151,6 +153,9 @@ int test() {
expect("greater_than_int(x, 3)", "", &errors);
expect("greater_than_int(3, x)", "", &errors);
+ // big string
+ expect(std::string(8192, 's').c_str(), std::string(8192, 's').c_str(), &errors);
+
printf("\n");
return errors;