コード例 #1
0
// copy constructor
TEST(IntLinkedList, COPY_CONSTRUCTOR_2) {
  LinkedList<int> lst;
  unsigned int i;
  int values[6] = { -13, 42, 95, -7, 113, -7 };
  int s;
  for(i = 0; i < sizeof(values)/sizeof(values[0]); i++)
    {
      s = values[i];
      if(!lst.Exists(s))
        {
          EXPECT_EQ(lst.Insert(s), true);
        }
      else
        {
          EXPECT_EQ(lst.Insert(s), false);
        }
      EXPECT_EQ(lst.Exists(s), true);
    }

  LinkedList<int> lst_copy(lst);

  for(i = 0; i < sizeof(values)/sizeof(values[0]); i++)
    {
      s = values[i];
      EXPECT_EQ(lst_copy.Exists(s), true);
    }
}
コード例 #2
0
ファイル: proc.c プロジェクト: mycoboco/beluga
/*
 *  preprocesses input tokens to form the output list
 */
void (proc_prep)(void)
{
    lex_t *t = lst_nexti();

    while (1) {
        switch(state) {
            case SINIT:
            case SAFTRNL:
                while (1) {
                    SKIPSP(t);
                    switch(t->id) {
                        case LEX_NEWLINE:
                            lst_flush(1);
                            t = lst_nexti();
                            continue;
                        case LEX_SHARP:
                            state++;
                            assert(state == SIDIREC || state == SDIREC);
                            lex_direc = 1;
                            goto loop;
                        default:
                            state = SNORM;
                            goto loop;
                        case LEX_EOI:
                            if (mg_state == MG_SENDIF && state == SINIT)
                                mg_once();
                            cond_finalize();
                            if (inc_isffile()) {
                                lst_flush(1);
                                return;
                            }
                            if (main_opt()->pponly) {
                                lex_t *u = lst_copy(t, 0, strg_line);
                                u->id = LEX_NEWLINE;
                                u->f.sync = 2;
                                u = lst_append(u, lex_make(0, NULL, 0));
                                lst_output(u);
                                lst_discard(1);    /* discards EOI */
                                in_switch(NULL, 0);    /* pop */
                                t = lst_nexti();
                                u->pos = t->pos;
                            } else {
                                lst_discard(1);    /* discards EOI */
                                in_switch(NULL, 0);    /* pop */
                                t = lst_nexti();
                            }
                            setdirecst(t);
                            assert(state == SAFTRNL || state == SINIT);
                            goto loop;
                    }
                }
                /* assert(!"impossible control flow - should never reach here");
                   break; */
            case SIDIREC:
            case SDIREC:
                directive(t);
                t = lst_nexti();    /* token after newline */
                setdirecst(t);
                break;
            case SNORM:
                while (t->id != LEX_NEWLINE) {
                    assert(t->id != LEX_EOI);
                    if (t->id == LEX_ID && !t->f.blue)
                        mcr_expand(t);
                    t = lst_nexti();
                }
                lst_flush(1);
                state = SAFTRNL;
                return;    /* at least newline flushed */
            case SIGN:
                do {
                    SKIPSP(t);
                    if (t->id == LEX_SHARP) {
                        state = SDIREC;
                        lex_direc = 1;
                        goto loop;
                    }
                    SKIPNL(t);
                    t = lst_nexti();
                } while(t->id != LEX_EOI);
                state = SAFTRNL;
                break;
            default:
                assert(!"invalid state -- should never reach here");
                break;
        }
        loop:
            ;
    }
}
コード例 #3
0
ファイル: proc.c プロジェクト: mycoboco/beluga
/*
 *  accepts #include;
 *  cannot use snbuf() because of a call to inc_start()
 */
static lex_t *dinclude(const lmap_t *pos)
{
    static char buf[64+1];    /* size must be (power of 2) + 1 */

    lex_t *t;
    const lmap_t *hpos;
    const char *inc = NULL;
    char *pbuf = buf, *p;

    lst_assert();
    lex_inc = 1;
    NEXTSP(t);    /* consumes include */
    hpos = t->pos;
    if (t->id == LEX_HEADER) {
        inc = LEX_SPELL(t);
        while (1) {
            NEXTSP(t);    /* consumes header or current token */
            if (t->id == LEX_NEWLINE)
                break;
            assert(t->id != LEX_EOI);
            if (t->id == LEX_ID && !t->f.blue && mcr_expand(t))
                continue;
            t = xtratok(t);
            break;
        }
    } else {
        int st = 0;    /* initial */
        size_t blen, slen;
        const lmap_t *epos = NULL;

        while (t->id != LEX_NEWLINE) {
            assert(t->id != LEX_EOI);
            epos = t->pos;
            if (t->id == LEX_ID && !t->f.blue && mcr_expand(t)) {
                NEXTSP(t);    /* consumes expanded id */
                continue;
            }
            assert(t->id != LEX_NEWLINE);
            switch(st) {
                case 0:    /* initial */
                    hpos = t->pos;
                    switch(t->id) {
                        case LEX_SCON:
                            if (t->spell[0] == 'L') {
                                default:
                                    SKIPNL(t);
                                    continue;
                            }
                            /* no break */
                        case LEX_HEADER:
                            st = 1;
                            inc = LEX_SPELL(t);
                            break;
                        case '<':
                            assert(pbuf == buf);
                            st = 2;
                            p = pbuf;
                            blen = sizeof(buf) - 1;
                            *p++ = '<';
                            break;
                    }
                    break;
                case 1:    /* extra tokens */
                    t = xtratok(t);
                    continue;
                case 2:    /* < seen */
                    slen = strlen(t->spell);
                    if (slen > blen - (p-pbuf)) {
                        const char *oldp = pbuf;
                        blen += ((slen + NELEM(buf)-2) & ~(size_t)(NELEM(buf)-2));
                        if (pbuf == buf) {
                            pbuf = MEM_ALLOC(blen + 1);
                            strcpy(pbuf, oldp);
                        } else
                            MEM_RESIZE(pbuf, blen + 1);
                        p = pbuf + (p - oldp);
                    }
                    strcpy(p, t->spell);
                    p += slen;
                    if (t->id == '>') {
                        st = 1;
                        inc = pbuf;
                        err_dpos(lmap_range(hpos, t->pos), ERR_PP_COMBINEHDR);
                    }
                    break;
                default:
                    assert(!"invalid state -- should never reach here");
                    break;
            }
            NEXTSP(t);    /* consumes handled token */
        }
        if (inc)
            hpos = lmap_range(hpos, epos);
        else
            err_dpos(lmap_after(pos), ERR_PP_NOHEADER);
    }

    if (!inc || !inc_start(inc, hpos))
        in_nextline();    /* because lex_inc set */
    else if (main_opt()->pponly) {
        t->f.sync = 1;
        lst_output(lst_copy(t, 0, strg_line));
    }

    if (pbuf != buf)
        MEM_FREE(pbuf);
    lex_inc = 0;
    return t;
}