@@ -282,7 +282,7 @@ Access Parser::parseAccess() {
282
282
consume (Token::identifier);
283
283
names.push_back (tensorName);
284
284
285
- vector<IndexVar > varlist;
285
+ vector<std::shared_ptr<IndexVarInterface> > varlist;
286
286
if (content->currentToken == Token::underscore) {
287
287
consume (Token::underscore);
288
288
if (content->currentToken == Token::lcurly) {
@@ -322,8 +322,8 @@ Access Parser::parseAccess() {
322
322
if (util::contains (content->tensorDimensions , tensorName)) {
323
323
tensorDimensions[i] = content->tensorDimensions .at (tensorName)[i];
324
324
}
325
- else if (util::contains (content->indexVarDimensions , varlist[i])) {
326
- tensorDimensions[i] = content->indexVarDimensions .at (varlist[i]);
325
+ else if (util::contains (content->indexVarDimensions , varlist[i]-> getIndexVar () )) {
326
+ tensorDimensions[i] = content->indexVarDimensions .at (varlist[i]-> getIndexVar () );
327
327
}
328
328
else {
329
329
tensorDimensions[i] = content->defaultDimension ;
@@ -347,8 +347,8 @@ Access Parser::parseAccess() {
347
347
return tensor (varlist);
348
348
}
349
349
350
- vector<IndexVar > Parser::parseVarList () {
351
- vector<IndexVar > varlist;
350
+ vector<std::shared_ptr<IndexVarInterface> > Parser::parseVarList () {
351
+ vector<std::shared_ptr<IndexVarInterface> > varlist;
352
352
varlist.push_back (parseVar ());
353
353
while (content->currentToken == Token::comma) {
354
354
consume (Token::comma);
@@ -357,13 +357,78 @@ vector<IndexVar> Parser::parseVarList() {
357
357
return varlist;
358
358
}
359
359
360
- IndexVar Parser::parseVar () {
360
+ std::shared_ptr<IndexVarInterface> Parser::parseVar () {
361
361
if (content->currentToken != Token::identifier) {
362
362
throw ParseError (" Expected index variable" );
363
363
}
364
364
IndexVar var = getIndexVar (content->lexer .getIdentifier ());
365
365
consume (Token::identifier);
366
- return var;
366
+ // If there is a paren after this identifier, then we may have a window
367
+ // or index set access.
368
+ if (this ->content ->currentToken == Token::lparen) {
369
+ this ->consume (Token::lparen);
370
+ switch (this ->content ->currentToken ) {
371
+ case Token::int_scalar: {
372
+ // In this case, we have a window or strided window. Start off by
373
+ // parsing the lo and hi of the window.
374
+ int lo, hi;
375
+ // Parse out lo.
376
+ std::istringstream value (this ->content ->lexer .getIdentifier ());
377
+ value >> lo;
378
+ this ->consume (Token::int_scalar);
379
+
380
+ // Parse the comma.
381
+ this ->consume (Token::comma);
382
+
383
+ // Parse out hi.
384
+ value = std::istringstream (this ->content ->lexer .getIdentifier ());
385
+ value >> hi;
386
+ this ->consume (Token::int_scalar);
387
+
388
+ // Now, there might be the stride. If there is another comma, then there
389
+ // is a stride value to parse. Otherwise, it's just the window of (lo, hi).
390
+ if (this ->content ->currentToken == Token::comma) {
391
+ this ->consume (Token::comma);
392
+ int stride;
393
+ value = std::istringstream (this ->content ->lexer .getIdentifier ());
394
+ value >> stride;
395
+ this ->consume (Token::int_scalar);
396
+ this ->consume (Token::rparen);
397
+ return std::make_shared<WindowedIndexVar>(var (lo, hi, stride));
398
+ } else {
399
+ this ->consume (Token::rparen);
400
+ return std::make_shared<WindowedIndexVar>(var (lo, hi));
401
+ }
402
+ }
403
+ case Token::lcurly: {
404
+ // If we see a curly brace, then an index set is being applied to the
405
+ // IndexVar. So, we'll parse a list of integers.
406
+ this ->consume (Token::lcurly);
407
+ std::vector<int > indexSet;
408
+ bool first = true ;
409
+ do {
410
+ // If this isn't the first iteration of the loop, consume a comma.
411
+ if (!first) {
412
+ this ->consume (Token::comma);
413
+ }
414
+ first = false ;
415
+ // Parse and consume the next integer.
416
+ std::istringstream value (this ->content ->lexer .getIdentifier ());
417
+ int index ;
418
+ value >> index ;
419
+ indexSet.push_back (index );
420
+ this ->consume (Token::int_scalar);
421
+ // Break when we hit a '}' to end the list.
422
+ } while (this ->content ->currentToken != Token::rcurly);
423
+ this ->consume (Token::rcurly);
424
+ this ->consume (Token::rparen);
425
+ return std::make_shared<IndexSetVar>(var (indexSet));
426
+ }
427
+ default :
428
+ throw ParseError (" Expected windowing expression." );
429
+ }
430
+ }
431
+ return std::make_shared<IndexVar>(var);
367
432
}
368
433
369
434
bool Parser::hasIndexVar (std::string name) const {
0 commit comments