diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-24 00:04:39 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-24 00:04:39 -0600 |
commit | f939f4bacb23cfe0c4fb96c5d71f30412fa828d7 (patch) | |
tree | baa140cc0ca283d08bda6c433610c09fc741b8da /src | |
parent | ddf5a43a66a91009e7fa33a689aac45e73c4dc97 (diff) | |
download | chill-f939f4bacb23cfe0c4fb96c5d71f30412fa828d7.tar.gz chill-f939f4bacb23cfe0c4fb96c5d71f30412fa828d7.tar.bz2 chill-f939f4bacb23cfe0c4fb96c5d71f30412fa828d7.zip |
binary op precedence
Diffstat (limited to 'src')
-rw-r--r-- | src/chillASTs.cc | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 29bc59a..170e481 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -1923,11 +1923,11 @@ void chillAST_BinaryOperator::dump(int indent, FILE *fp) { fflush(fp); } -void chillAST_BinaryOperator::print(int indent, FILE *fp) { // TODO this needparens logic is wrong +void chillAST_BinaryOperator::print(int indent, FILE *fp) { printPreprocBEFORE(indent, fp); chillindent(indent, fp); - bool needparens = getPrec()<=lhs->getPrec(); + bool needparens = getPrec()<lhs->getPrec(); if (needparens) fprintf(fp, "("); if (lhs) lhs->print(0, fp); @@ -5620,11 +5620,42 @@ void chillAST_Preprocessing::print(int indent, FILE *fp) { // probably very wro if (position == CHILLAST_PREPROCESSING_LINEBEFORE) { - //fprintf(fp, "\n"); // comment seems to have \n at the end already - //chillindent(indent, fp); } - //if (pptype != CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILLAST_PREPROCESSING_UNKNOWN) fprint(fp, "\n"); } + +//! I'm just a bit lazy to write ifs ... +const char* binaryPrec[] = { + " :: ", + " . -> ", + "", + " .* ->* ", + " * / % ", + " + - ", + " << >> ", + " < <= > >=", + " == != ", + " & ", + " ^ ", + " | ", + " && ", + " || ", + " = += -= *= /= %= <<= >>= &= ^= |= ", + " , " +}; + +bool opInSet(const char* set,char* op) { + string tmp = op; + tmp=" "+tmp+" "; + return strstr(set, tmp.c_str()) != NULL; +} + +int chillAST_BinaryOperator::getPrec() { + for (int i = 0; i< 15;++i) + if (opInSet(binaryPrec[i],op)) return INT8_MAX+i; + return INT8_MAX; +} + +// TODO add unary
\ No newline at end of file |