forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty_alg.c
More file actions
60 lines (51 loc) · 1.6 KB
/
pretty_alg.c
File metadata and controls
60 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/** \file pretty_alg.c
* split out of exppp.c 9/21/13
*/
#include <express/scope.h>
#include <express/linklist.h>
#include <exppp/exppp.h>
#include "pp.h"
#include "pretty_type.h"
#include "pretty_expr.h"
#include "pretty_scope.h"
#include "pretty_alg.h"
void ALGscope_out( Scope s, int level ) {
SCOPEtypes_out( s, level );
SCOPEentities_out( s, level );
SCOPEalgs_out( s, level );
SCOPEconsts_out( s, level );
SCOPElocals_out( s, level );
}
/** last arg is not terminated with ; or \n */
void ALGargs_out( Linked_List args, int level ) {
Type previoustype = 0;
bool previousVAR = false;
indent2 = level + exppp_continuation_indent;
/* combine adjacent parameters that have the same type and VAR-ness
*
* According to the EBNF, only procedures can use 'VAR', and it applies
* to all params in the same type assignment statement.
* flags.var is set in the formal_parameter production
*/
LISTdo( args, v, Variable ) {
if( ( previoustype != v->type ) || ( previousVAR != v->flags.var ) ) {
if( previoustype ) {
wrap( " : " );
TYPE_head_out( previoustype, NOLEVEL );
raw( ";\n" );
}
raw( "%*s", level, "" );
if( v->flags.var ) {
raw( "VAR " );
}
EXPR_out( VARget_name( v ), 0 );
} else {
raw( ", " );
EXPR_out( VARget_name( v ), 0 );
}
previoustype = v->type;
previousVAR = v->flags.var;
} LISTod
wrap( " : " );
TYPE_head_out( previoustype, NOLEVEL );
}