Lines Matching defs:tok

73 	struct isl_token *tok = isl_alloc_type(ctx, struct isl_token);
74 if (!tok)
76 tok->line = line;
77 tok->col = col;
78 tok->on_new_line = on_new_line;
79 tok->is_keyword = 0;
80 tok->u.s = NULL;
81 return tok;
84 /* Return the type of "tok".
86 int isl_token_get_type(struct isl_token *tok)
88 return tok ? tok->type : ISL_TOKEN_ERROR;
93 __isl_give isl_val *isl_token_get_val(isl_ctx *ctx, struct isl_token *tok)
95 if (!tok)
97 if (tok->type != ISL_TOKEN_VALUE)
101 return isl_val_int_from_isl_int(ctx, tok->u.v);
106 isl_bool isl_token_has_str(struct isl_token *tok)
108 if (!tok)
110 return isl_bool_ok(tok->u.s != NULL);
115 __isl_give char *isl_token_get_str(isl_ctx *ctx, struct isl_token *tok)
117 if (!tok)
119 if (!tok->u.s)
124 return strdup(tok->u.s);
127 void isl_token_free(struct isl_token *tok)
129 if (!tok)
131 if (tok->type == ISL_TOKEN_VALUE)
132 isl_int_clear(tok->u.v);
133 else if (tok->type == ISL_TOKEN_MAP)
134 isl_map_free(tok->u.map);
135 else if (tok->type == ISL_TOKEN_AFF)
136 isl_pw_aff_free(tok->u.pwaff);
138 free(tok->u.s);
139 free(tok);
142 void isl_stream_error(__isl_keep isl_stream *s, struct isl_token *tok,
145 int line = tok ? tok->line : s->line;
146 int col = tok ? tok->col : s->col;
154 if (tok) {
155 if (tok->type < 256)
156 fprintf(stderr, "got '%c'\n", tok->type);
157 else if (tok->type == ISL_TOKEN_IDENT)
158 fprintf(stderr, "got ident '%s'\n", tok->u.s);
159 else if (tok->is_keyword)
160 fprintf(stderr, "got keyword '%s'\n", tok->u.s);
161 else if (tok->type == ISL_TOKEN_VALUE) {
163 isl_int_print(stderr, tok->u.v, 0);
165 } else if (tok->type == ISL_TOKEN_MAP) {
169 p = isl_printer_print_map(p, tok->u.map);
172 } else if (tok->type == ISL_TOKEN_AFF) {
176 p = isl_printer_print_pw_aff(p, tok->u.pwaff);
179 } else if (tok->u.s)
180 fprintf(stderr, "got token '%s'\n", tok->u.s);
182 fprintf(stderr, "got token type %d\n", tok->type);
311 void isl_stream_push_token(__isl_keep isl_stream *s, struct isl_token *tok)
314 s->tokens[s->n_token++] = tok;
390 struct isl_token *tok = NULL;
440 tok = isl_token_new(s->ctx, line, col, old_line != line);
441 if (!tok)
443 tok->type = (enum isl_token_type)c;
444 return tok;
449 tok = isl_token_new(s->ctx, line, col, old_line != line);
450 if (!tok)
452 tok->u.s = strdup("->");
453 tok->type = ISL_TOKEN_TO;
454 return tok;
458 tok = isl_token_new(s->ctx, line, col, old_line != line);
459 if (!tok)
461 tok->type = (enum isl_token_type) '-';
462 return tok;
466 tok = isl_token_new(s->ctx, line, col, old_line != line);
467 if (!tok)
469 tok->type = ISL_TOKEN_VALUE;
470 isl_int_init(tok->u.v);
479 isl_int_read(tok->u.v, s->buffer);
480 if (minus && isl_int_is_zero(tok->u.v)) {
481 tok->col++;
482 tok->on_new_line = 0;
483 isl_stream_push_token(s, tok);
484 tok = isl_token_new(s->ctx, line, col, old_line != line);
485 if (!tok)
487 tok->type = (enum isl_token_type) '-';
489 return tok;
492 tok = isl_token_new(s->ctx, line, col, old_line != line);
493 if (!tok)
506 tok->type = check_keywords(s);
507 if (tok->type != ISL_TOKEN_IDENT)
508 tok->is_keyword = 1;
509 tok->u.s = strdup(s->buffer);
510 if (!tok->u.s)
512 return tok;
515 tok = isl_token_new(s->ctx, line, col, old_line != line);
516 if (!tok)
518 tok->type = ISL_TOKEN_STRING;
519 tok->u.s = NULL;
527 tok->u.s = strdup(s->buffer);
528 return tok;
532 tok = isl_token_new(s->ctx, line, col, old_line != line);
533 if (!tok)
536 tok->u.s = strdup("==");
537 tok->type = ISL_TOKEN_EQ_EQ;
538 return tok;
542 tok->type = (enum isl_token_type) '=';
543 return tok;
547 tok = isl_token_new(s->ctx, line, col, old_line != line);
548 if (!tok)
551 tok->u.s = strdup(":=");
552 tok->type = ISL_TOKEN_DEF;
553 return tok;
557 tok->type = (enum isl_token_type) ':';
558 return tok;
562 tok = isl_token_new(s->ctx, line, col, old_line != line);
563 if (!tok)
566 tok->u.s = strdup(">=");
567 tok->type = ISL_TOKEN_GE;
568 return tok;
571 tok->u.s = strdup(">>=");
572 tok->type = ISL_TOKEN_LEX_GE;
573 return tok;
575 tok->u.s = strdup(">>");
576 tok->type = ISL_TOKEN_LEX_GT;
578 tok->u.s = strdup(">");
579 tok->type = ISL_TOKEN_GT;
583 return tok;
587 tok = isl_token_new(s->ctx, line, col, old_line != line);
588 if (!tok)
591 tok->u.s = strdup("<=");
592 tok->type = ISL_TOKEN_LE;
593 return tok;
596 tok->u.s = strdup("<<=");
597 tok->type = ISL_TOKEN_LEX_LE;
598 return tok;
600 tok->u.s = strdup("<<");
601 tok->type = ISL_TOKEN_LEX_LT;
603 tok->u.s = strdup("<");
604 tok->type = ISL_TOKEN_LT;
608 return tok;
611 tok = isl_token_new(s->ctx, line, col, old_line != line);
612 if (!tok)
614 tok->type = ISL_TOKEN_AND;
616 tok->u.s = strdup("&");
619 tok->u.s = strdup("&&");
620 return tok;
623 tok = isl_token_new(s->ctx, line, col, old_line != line);
624 if (!tok)
626 tok->type = ISL_TOKEN_OR;
628 tok->u.s = strdup("|");
631 tok->u.s = strdup("||");
632 return tok;
635 tok = isl_token_new(s->ctx, line, col, old_line != line);
636 if (!tok)
639 tok->u.s = strdup("/\\");
640 tok->type = ISL_TOKEN_AND;
641 return tok;
643 tok->u.s = strdup("//");
644 tok->type = ISL_TOKEN_INT_DIV;
645 return tok;
647 tok->type = (enum isl_token_type) '/';
651 return tok;
654 tok = isl_token_new(s->ctx, line, col, old_line != line);
655 if (!tok)
658 tok->type = (enum isl_token_type) '\\';
661 tok->u.s = strdup("\\/");
662 tok->type = ISL_TOKEN_OR;
664 return tok;
667 tok = isl_token_new(s->ctx, line, col, old_line != line);
668 if (!tok)
671 tok->u.s = strdup("!=");
672 tok->type = ISL_TOKEN_NE;
673 return tok;
675 tok->type = ISL_TOKEN_NOT;
676 tok->u.s = strdup("!");
680 return tok;
683 tok = isl_token_new(s->ctx, line, col, old_line != line);
684 if (!tok)
686 tok->type = ISL_TOKEN_UNKNOWN;
687 return tok;
689 isl_token_free(tok);
705 struct isl_token *tok;
707 tok = isl_stream_next_token(s);
708 if (!tok)
710 if (tok->type == type) {
711 isl_token_free(tok);
714 isl_stream_push_token(s, tok);
720 struct isl_token *tok;
723 tok = isl_stream_next_token(s);
724 if (!tok)
726 r = tok->type == type;
727 isl_stream_push_token(s, tok);
733 struct isl_token *tok;
735 tok = isl_stream_next_token(s);
736 if (!tok)
738 if (tok->type == ISL_TOKEN_IDENT) {
739 char *ident = strdup(tok->u.s);
740 isl_token_free(tok);
743 isl_stream_push_token(s, tok);
749 struct isl_token *tok;
751 tok = isl_stream_next_token(s);
752 if (!tok) {
757 if (tok->type == type) {
758 isl_token_free(tok);
761 isl_stream_error(s, tok, "expecting other token");
762 isl_token_free(tok);
768 struct isl_token *tok;
770 tok = isl_stream_next_token(s);
772 if (!tok)
775 isl_stream_push_token(s, tok);
811 struct isl_token *tok = isl_stream_next_token(s);
812 isl_stream_error(s, tok, "unexpected token");
813 isl_token_free(tok);
968 struct isl_token *tok;
985 tok = isl_stream_next_token(s);
986 if (!tok) {
991 if (tok->type == ':') {
992 isl_token_free(tok);
997 isl_stream_error(s, tok, "expecting ':'");
998 isl_stream_push_token(s, tok);
1008 tok = isl_stream_next_token(s);
1009 if (!tok)
1011 indent = tok->col - 1;
1012 isl_stream_push_token(s, tok);
1026 tok = isl_stream_next_token(s);
1027 if (!tok) {
1032 if (tok->type == '-') {
1033 isl_token_free(tok);
1038 isl_stream_error(s, tok, "expecting '-'");
1039 isl_stream_push_token(s, tok);
1044 tok = isl_stream_next_token(s);
1045 if (!tok)
1047 indent = tok->col - 1;
1048 if (indent < get_yaml_indent(s) || tok->type != '-') {
1049 isl_stream_push_token(s, tok);
1052 isl_token_free(tok);
1072 struct isl_token *tok;
1078 tok = isl_stream_next_token(s);
1079 if (!tok) {
1084 if (isl_token_get_type(tok) == '{') {
1085 isl_token_free(tok);
1088 indent = tok->col - 1;
1089 isl_stream_push_token(s, tok);
1104 struct isl_token *tok;
1113 tok = isl_stream_next_token(s);
1114 if (!tok)
1117 indent = tok->col - 1;
1118 isl_stream_push_token(s, tok);
1141 struct isl_token *tok;
1147 tok = isl_stream_next_token(s);
1148 if (!tok) {
1153 if (isl_token_get_type(tok) == '[') {
1154 isl_token_free(tok);
1157 indent = tok->col - 1;
1158 isl_stream_push_token(s, tok);
1174 struct isl_token *tok;
1184 tok = isl_stream_next_token(s);
1185 if (!tok)
1188 indent = tok->col - 1;
1189 dash = tok->type == '-';
1190 isl_stream_push_token(s, tok);