History

improved instruction dump line info; fixed examples typos

Ge Wang committed 3 years ago

Commit 1038f5a1 parent 4f3e7308 files · +132 −27Browse files

Showing the changes to src/core/chuck_parse.cpp (1 of 8 files). Show all

Unified · Split

src/core/chuck_parse.cpp+66−14
@@ -316,6 +316,22 @@ string absyn2str( a_Exp exp ) · 315 unmodified lines
316316
317317
318318
319+//-----------------------------------------------------------------------------
320+// name: name_demangle()
321+// desc: demangle chuck function names
322+// e.g., input: "version@0@Machine" output: "version"
323+//-----------------------------------------------------------------------------
324+string name_demangle( const string & name )
325+{
326+ // find the first @
327+ size_t pos = name.find_first_of('@');
328+ // if found, substring
329+ return ( pos != string::npos ) ? name.substr(0,pos) : name;
330+}
331+
332+
333+
334+
319335 //-----------------------------------------------------------------------------
320336 // name: absyn_exp2str()
321337 // desc: convert abstract syntax exp to string
@@ -387,7 +403,7 @@ string absyn_exp2str( a_Exp exp, t_CKBOOL iterate ) · 65 unmodified lines
387403 // next
388404 exp = exp->next;
389405 // if more
390− if( exp ) str += ", ";
406+ if( exp ) str += ",";
391407 }
392408
393409 return str;
@@ -467,10 +483,48 @@ string absyn_op2str( ae_Operator op ) · 73 unmodified lines
467483 //-----------------------------------------------------------------------------
468484 string absyn_binary2str( a_Exp_Binary binary )
469485 {
486+ string lhs = absyn_exp2str(binary->lhs);
487+ string op = absyn_op2str(binary->op);
488+ string rhs = absyn_exp2str(binary->rhs);
489+
490+ // use paren?
491+ bool paren = false;
492+ // spacing?
493+ bool spacing = false;
494+
495+ switch(binary->op)
496+ {
497+ case ae_op_plus_chuck:
498+ case ae_op_minus_chuck:
499+ case ae_op_times_chuck:
500+ case ae_op_divide_chuck:
501+ case ae_op_s_or_chuck:
502+ case ae_op_s_and_chuck:
503+ case ae_op_shift_left_chuck:
504+ case ae_op_shift_right_chuck:
505+ case ae_op_percent_chuck:
506+ case ae_op_s_xor_chuck:
507+ case ae_op_chuck:
508+ case ae_op_unchuck:
509+ case ae_op_upchuck:
510+ case ae_op_lt:
511+ case ae_op_gt:
512+ case ae_op_le:
513+ case ae_op_ge:
514+ case ae_op_at_chuck:
515+ paren = false;
516+ spacing = true;
517+ break;
518+ default:
519+ paren = true;
520+ spacing = false;
521+ break;
522+ }
523+
470524 // (lhs OP rhs)
471− return "(" + absyn_exp2str(binary->lhs)
472− + absyn_op2str(binary->op)
473− + absyn_exp2str(binary->rhs) + ")";
525+ string str = string(paren?"(":"") + lhs + (spacing?" ":"") + op + (spacing?" ":"") + rhs + (paren?")":"");
526+ // return
527+ return str;
474528 }
475529
476530
@@ -495,7 +549,7 @@ string absyn_unary2str( a_Exp_Unary unary ) · 18 unmodified lines
495549 string absyn_cast2str( a_Exp_Cast cast )
496550 {
497551 Chuck_Type * to = cast->self->type;
498− return "$ " + to->name;
552+ return absyn_exp2str(cast->exp) + "$" + to->name;
499553 }
500554
501555
@@ -538,9 +592,9 @@ string absyn_primary2str( a_Exp_Primary primary ) · 36 unmodified lines
538592 {
539593 case ae_primary_var: str = S_name(primary->var); break;
540594 case ae_primary_num: str = to_string(primary->num); break;
541− case ae_primary_float: str = primary->fnum; break;
542− case ae_primary_str: str = primary->str; break;
543− case ae_primary_char: str = primary->chr; break;
595+ case ae_primary_float: str = to_string(primary->fnum); break;
596+ case ae_primary_str: str = string("\"") + primary->str + "\""; break;
597+ case ae_primary_char: str = string("'") + primary->chr + "'"; break;
544598 case ae_primary_array: str = "["+absyn_exp2str(primary->array->exp_list)+"]"; break;
545599 case ae_primary_complex: str = "#("+absyn_exp2str(primary->complex->re)+")"; break;
546600 case ae_primary_polar: str = "%("+absyn_exp2str(primary->polar->mod)+")"; break;
@@ -564,10 +618,7 @@ string absyn_primary2str( a_Exp_Primary primary ) · 17 unmodified lines
564618 string absyn_array2str( a_Exp_Array array )
565619 {
566620 string str;
567−
568− t_CKUINT depth = 0;
569621 a_Array_Sub sub = NULL;
570− t_CKBOOL is_str = FALSE;
571622
572623 // get the sub
573624 sub = array->indices;
@@ -600,7 +651,7 @@ string absyn_func_call2str( a_Exp_Func_Call func_call ) · 26 unmodified lines
600651 {
601652 string str;
602653 // function name
603− str = absyn_exp2str( func_call->func );
654+ str = name_demangle( absyn_exp2str( func_call->func ) );
604655 // args
605656 str += "(" + absyn_exp2str( func_call->args ) + ")";
606657 // done
@@ -616,7 +667,8 @@ string absyn_func_call2str( a_Exp_Func_Call func_call ) · 9 unmodified lines
616667 //-----------------------------------------------------------------------------
617668 string absyn_dot_member2str( a_Exp_Dot_Member dot_member )
618669 {
619− return absyn_exp2str(dot_member->base) + "." + S_name(dot_member->xid);
670+ // return
671+ return absyn_exp2str(dot_member->base) + "." + name_demangle(S_name(dot_member->xid));
620672 }
621673
622674
@@ -651,7 +703,7 @@ string absyn_decl2str( a_Exp_Decl decl ) · 28 unmodified lines
651703 while( list )
652704 {
653705 // type
654− str += list->var_decl->value->type->name + " " + (decl->type->ref ? "@" : "") + list->var_decl->value->name;
706+ str += list->var_decl->value->type->name + " " + (decl->type->ref && !list->var_decl->array ? "@ " : "") + list->var_decl->value->name;
655707 // array?
656708 if( list->var_decl->array )
657709 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t