input_scan.h 21.9 KB
Newer Older
1
/* #######################################################################
2
# Copyright (c) 2019-2020 COBOLworx Corporation
3 4 5 6 7 8 9 10 11 12 13
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in
#      the documentation and/or other materials provided with the
#      distribution.
14
#    * Neither the name of the COBOLworx Corporation nor the names of its
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#      contributors may be used to endorse or promote products derived
#      from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
############################################################################ */

31 32
#pragma once

33
#include <stdlib.h>
34 35
#include <string>
#include <vector>
36 37
#include <map>
#include <set>
38 39
#include <fstream>
#include <sstream>
40
#include <iomanip>
41 42
#include "profiler.h"
#include "utils.h"
43
#include "vartree.h"
44 45 46 47 48 49 50 51

#ifndef EQ
#define EQ ==
#define AND &&
#define OR ||
#define NEEDED_TO_DEFINE_EQ
#endif

52 53 54 55
#if __GNUC__ < 7
#define nullptr NULL
#endif

56

57 58 59 60 61 62 63 64 65 66 67 68 69 70
//////////////////////////////////////////////////////////////////////////
// These data structures are based on from GnuCOBOL3.1-dev/libcob/common.h
//////////////////////////////////////////////////////////////////////////

/*  It should be noted that we have two, or perhaps three, sources of
    of data size.  There is the summary in source.cbl.list, there is
    the size in COB_DATA, and there is the size field in COB_FIELD.

    I've seen cases where they don't quite match.  There will be code to
    check that, but wariness is indicated.  RJD, 2020-05-12
    */

class COB_PIC_SYMBOLS;
class COB_PIC_SYMBOL
71 72
{
public:
73 74 75 76 77 78 79 80 81 82 83
    std::string         name;       /* name of pic_symbol */
    std::string         pic_symbol;
public:
    COB_PIC_SYMBOL(const std::string &n, const std::string &p)
    {
        name = n;
        pic_symbol = p;
    }
    friend COB_PIC_SYMBOLS;
};
typedef std::vector<COB_PIC_SYMBOL> V_COB_PIC_SYMBOLS;
84
typedef std::map<std::string,size_t> M_COB_PIC_SYMBOLS;
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

class COB_PIC_SYMBOLS
{
private:
    V_COB_PIC_SYMBOLS v_pic_symbols;
    M_COB_PIC_SYMBOLS m_pic_symbols;

public:
    COB_PIC_SYMBOLS()
    {
    }
    void
    Insert(const std::string &name, const std::string &pic_symbol)
    {
        M_COB_PIC_SYMBOLS::const_iterator it = m_pic_symbols.find(name);
        if( it != m_pic_symbols.end() ) {
            std::cout << "Creating the symbol " << name << " more than once in COB_PIC_SYMBOLS::Insert()\n" ;
            exit(1);
        }
104

105 106 107 108 109 110
        COB_PIC_SYMBOL cps(name, pic_symbol);
        m_pic_symbols[name] = v_pic_symbols.size();
        v_pic_symbols.push_back(cps);
    }
    void
    Dump() const
111
    {
112 113 114 115 116
        std::cout << "COB_PIC_SYMBOLS:" << std::endl;
        std::cout << std::setw(20) << "name" ;
        std::cout << " ";
        std::cout << std::setw(20) << "pic_symbol";
        std::cout << std::endl;
117

118
        for( V_COB_PIC_SYMBOLS::const_iterator it = v_pic_symbols.begin();
119 120 121
                it != v_pic_symbols.end();
                it++) {
            const COB_PIC_SYMBOL symbol = *it;
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
            std::cout << std::setw(20) << symbol.name ;
            std::cout << " ";
            std::cout << std::setw(20) << symbol.pic_symbol;
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
    const COB_PIC_SYMBOL *
    GetPicSymbol(std::string const &pic_name) const
    {
        const COB_PIC_SYMBOL *retval = nullptr;
        M_COB_PIC_SYMBOLS::const_iterator it = m_pic_symbols.find(pic_name);
        if( it != m_pic_symbols.end() ) {
            retval = &v_pic_symbols[it->second];
        }
        return retval;
138 139 140
    }
};

141 142
class COB_DATA;
class COB_DATUM
143
{
144 145 146 147 148 149
public:
    std::string         name;         /* name of data field */
    int                 size;         /* size of the field  */
    std::string         program_id;   /* From a header comment*/
    std::string         storage_type; /* From .h file structure*/
    std::string         cbl_name;     /* From the comment in the .h code */
150

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
public:
    COB_DATUM(const std::string &name_,
              int size_,
              const std::string &program_id_,
              const std::string &storage_,
              const std::string &cbl_name_)
    {
        name = name_;
        size = size_;
        program_id = program_id_;
        storage_type = storage_;
        cbl_name = cbl_name_;
    }
    friend COB_DATA;
} ;
typedef std::vector<COB_DATUM> V_COB_DATUM;
167
typedef std::map<std::string,size_t> M_COB_DATUM;
168

169 170 171
class COB_DATA
{
public:
172 173 174
    V_COB_DATUM v_data; // The list of elements
    M_COB_DATUM m_data_from_b_field;
    M_COB_DATUM m_data_from_cbl_name;
175 176 177

public:
    COB_DATA()
178
    {
179 180 181 182 183 184 185 186
    }
    void
    Insert(const std::string &name,
           int size,
           const std::string &program_id,
           const std::string &storage,
           const std::string &cbl_name)
    {
187 188
        M_COB_DATUM::const_iterator it = m_data_from_b_field.find(name);
        if( it != m_data_from_b_field.end() ) {
189 190 191 192 193
            std::cout << "Creating the symbol " << name << " more than once in COB_DATA::Insert()\n" ;
            exit(1);
        }

        COB_DATUM cd(name, size, program_id, storage, cbl_name);
194 195 196 197 198 199 200
        m_data_from_b_field[name] = v_data.size();

        std::string cobol_name = program_id;
        cobol_name += "|";
        cobol_name += cbl_name;
        m_data_from_cbl_name[cobol_name] = v_data.size();

201
        v_data.push_back(cd);
202 203
    }

rdubner's avatar
rdubner committed
204
    void
205 206 207 208
    Dump() const
    {
        std::cout << "COB_DATA:" << std::endl;
        std::cout << std::setw(20) << "name" ;
209
        std::cout << std::setw(20) << "storage";
210 211 212 213
        std::cout << std::setw(20) << "size";
        std::cout << std::setw(20) << "program_id";
        std::cout << std::setw(20) << "cbl_name";
        std::cout << std::endl;
214

215

216 217 218 219
        for( V_COB_DATUM::const_iterator it=v_data.begin();
                it!= v_data.end();
                it++) {
            COB_DATUM symbol = *it;
220
            std::cout << std::setw(20) << symbol.name ;
221
            std::cout << std::setw(20) << symbol.storage_type;
222 223 224 225
            std::cout << std::setw(20) << symbol.size;
            std::cout << std::setw(20) << symbol.program_id;
            std::cout << std::setw(20) << symbol.cbl_name;
            std::cout << std::endl;
226
        }
227
        std::cout << std::endl;
228 229
    }

230 231 232 233
    const COB_DATUM *
    GetCobDatum(const std::string &b_name) const
    {
        const COB_DATUM *retval = nullptr;
234 235
        M_COB_DATUM::const_iterator it = m_data_from_b_field.find(b_name);
        if( it != m_data_from_b_field.end() ) {
236 237 238 239 240 241
            retval = &v_data[it->second];
        }

        return retval;
    }

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
    const COB_DATUM *
    GetCobDatumFromProgAndName(const std::string &prog,
                               const std::string &name) const
    {
        std::string cobol_name = prog;
        cobol_name += "|";
        cobol_name += name;

        const COB_DATUM *retval = nullptr;
        M_COB_DATUM::const_iterator it = m_data_from_cbl_name.find(cobol_name);
        if( it != m_data_from_cbl_name.end() ) {
            retval = &v_data[it->second];
        }

        return retval;
    }


260 261 262 263 264
};

class COB_FIELD_ATTRIBUTES;
class COB_FIELD_ATTRIBUTE
{
265
public:
rdubner's avatar
rdubner committed
266
    std::string         a_name;     /* name of attribute */
267 268 269 270
    unsigned short      type;       /* Field type        */
    unsigned short      digits;     /* Digit count       */
    signed short        scale;      /* Field scale       */
    unsigned short      flags;      /* Field flags       */
rdubner's avatar
rdubner committed
271
    std::string         p_name;     /* picture string    */
272
    std::string         program_id; /* picture string    */
273

274 275 276 277 278 279 280 281
public:
    COB_FIELD_ATTRIBUTE(std::string         name_,
                        unsigned short      type_,
                        unsigned short      digits_,
                        signed short        scale_,
                        unsigned short      flags_,
                        std::string         name_of_pic_,
                        std::string         program_id_)
282
    {
rdubner's avatar
rdubner committed
283
        a_name      = name_          ;
284 285 286 287
        type        = type_          ;
        digits      = digits_        ;
        scale       = scale_         ;
        flags       = flags_         ;
rdubner's avatar
rdubner committed
288
        p_name      = name_of_pic_   ;
289 290 291 292 293
        program_id  = program_id_    ;
    }
    friend COB_FIELD_ATTRIBUTES;
} ;
typedef std::vector<COB_FIELD_ATTRIBUTE> V_COB_FIELD_ATTRIBUTE;
294
typedef std::map<std::string,size_t> M_COB_FIELD_ATTRIBUTES;
295 296 297 298 299 300 301 302 303 304 305 306

class COB_FIELD_ATTRIBUTES
{
public:
    V_COB_FIELD_ATTRIBUTE  v_cob_field_attributes;
    M_COB_FIELD_ATTRIBUTES m_cob_field_attributes;

public:
    COB_FIELD_ATTRIBUTES()
    {
    }
    void
rdubner's avatar
rdubner committed
307
    Insert(std::string         a_name,     /* name of attribute */
308 309 310 311
           unsigned short      type,       /* Field type        */
           unsigned short      digits,     /* Digit count       */
           signed short        scale,      /* Field scale       */
           unsigned short      flags,      /* Field flags       */
rdubner's avatar
rdubner committed
312
           std::string         p_name,     /* picture string    */
313 314
           std::string         program_id) /* picture string    */
    {
rdubner's avatar
rdubner committed
315
        M_COB_FIELD_ATTRIBUTES::const_iterator it = m_cob_field_attributes.find(a_name);
316
        if( it != m_cob_field_attributes.end() ) {
rdubner's avatar
rdubner committed
317
            std::cout << "Creating the symbol " << a_name << " more than once in COB_FIELD_ATTRIBUTES::Insert()\n" ;
318
            exit(1);
319
        }
320

rdubner's avatar
rdubner committed
321
        COB_FIELD_ATTRIBUTE cfa(a_name,
322 323 324 325
                                type,
                                digits,
                                scale,
                                flags,
rdubner's avatar
rdubner committed
326
                                p_name,
327
                                program_id);
rdubner's avatar
rdubner committed
328
        m_cob_field_attributes[a_name] = v_cob_field_attributes.size();
329
        v_cob_field_attributes.push_back(cfa);
330 331
    }

332 333
    void
    Dump() const
334
    {
335
        std::cout << "COB_FIELD_ATTRIBUTES:" << std::endl;
rdubner's avatar
rdubner committed
336
        std::cout << std::setw(20) << "a_name" ;
337 338 339 340
        std::cout << std::setw(20) << "type";
        std::cout << std::setw(20) << "digits";
        std::cout << std::setw(20) << "scale" ;
        std::cout << std::setw(20) << "flags";
rdubner's avatar
rdubner committed
341
        std::cout << std::setw(20) << "p_name";
342 343
        std::cout << std::setw(20) << "program_id";
        std::cout << std::endl;
344
        for(V_COB_FIELD_ATTRIBUTE::const_iterator it=v_cob_field_attributes.begin();
345 346
                it!=v_cob_field_attributes.end();
                it++) {
347
            COB_FIELD_ATTRIBUTE attr = *it;
rdubner's avatar
rdubner committed
348
            std::cout << std::setw(20) << attr.a_name ;
349 350 351 352
            std::cout << std::setw(20) << attr.type;
            std::cout << std::setw(20) << attr.digits;
            std::cout << std::setw(20) << attr.scale ;
            std::cout << std::setw(20) << attr.flags;
rdubner's avatar
rdubner committed
353
            std::cout << std::setw(20) << attr.p_name;
354 355 356 357 358
            std::cout << std::setw(20) << attr.program_id;
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
359

360 361 362 363 364 365 366
    const COB_FIELD_ATTRIBUTE *
    GetFieldAttribute(const std::string &a_name) const
    {
        const COB_FIELD_ATTRIBUTE *retval = nullptr;
        M_COB_FIELD_ATTRIBUTES::const_iterator it = m_cob_field_attributes.find(a_name);
        if( it != m_cob_field_attributes.end() ) {
            retval = &v_cob_field_attributes[it->second];
367
        }
368

369 370
        return retval;
    }
371
};
372

373 374 375 376
class COB_FIELDS;
class COB_FIELD
{
public:
rdubner's avatar
rdubner committed
377 378 379 380 381 382 383
    std::string  f_name;       /* name of field         */
    std::string  b_name;       /* name of data field    */
    int          offset;       /* any internal + offset */
    int          size;         /* Field size            */
    std::string  a_name;       /* name of attribute     */
    std::string  program_id;   /* Where defined         */
    std::string  cbl_name;     /* From the comment in the .h code */
384

385
public:
rdubner's avatar
rdubner committed
386 387
    COB_FIELD(std::string f_name_,
              std::string b_name_,
388
              int         offset_,
rdubner's avatar
rdubner committed
389 390
              int         size_,
              std::string a_name_,
391 392 393
              std::string program_id_,
              std::string cbl_name_)
    {
rdubner's avatar
rdubner committed
394 395
        f_name       = f_name_      ;
        b_name       = b_name_      ;
396
        offset       = offset_    ;
rdubner's avatar
rdubner committed
397 398
        size         = size_      ;
        a_name       = a_name_      ;
399 400 401
        program_id   = program_id_;
        cbl_name     = cbl_name_  ;
    }
402

403 404 405
    friend COB_FIELDS;
} ;
typedef std::vector<COB_FIELD> V_COB_FIELDS;
406
typedef std::map<std::string,size_t> M_COB_FIELDS;
407 408 409 410 411 412 413 414 415 416 417

class COB_FIELDS
{
private:
    M_COB_FIELDS m_cob_fields;

public:
    V_COB_FIELDS v_cob_fields;

public:
    void
rdubner's avatar
rdubner committed
418 419
    Insert(std::string f_name,
           std::string b_name,
420
           int         offset,
rdubner's avatar
rdubner committed
421 422
           int         size,
           std::string a_name,
423 424
           std::string program_id,
           std::string cbl_name)
425
    {
rdubner's avatar
rdubner committed
426
        M_COB_FIELDS::const_iterator it = m_cob_fields.find(f_name);
427
        if( it != m_cob_fields.end() ) {
rdubner's avatar
rdubner committed
428
            std::cout << "Creating the symbol " << f_name << " more than once in COB_FIELDS::Insert()\n" ;
429 430
            exit(1);
        }
rdubner's avatar
rdubner committed
431 432
        COB_FIELD cf(f_name,
                     b_name,
433
                     offset,
rdubner's avatar
rdubner committed
434 435
                     size,
                     a_name,
436 437
                     program_id,
                     cbl_name);
rdubner's avatar
rdubner committed
438
        m_cob_fields[f_name] = v_cob_fields.size();
439
        v_cob_fields.push_back(cf);
440 441
    }

442
    void
rdubner's avatar
rdubner committed
443 444
    Modify(std::string f_name_,
           std::string b_name_,
445
           int         offset_)
446
    {
rdubner's avatar
rdubner committed
447
        M_COB_FIELDS::iterator it = m_cob_fields.find(f_name_);
448
        if( it EQ m_cob_fields.end() ) {
rdubner's avatar
rdubner committed
449
            std::cout << "Couldn't find symbol " << f_name_ << " COB_FIELDS::Modify()\n" ;
450 451 452
            exit(1);
        }
        size_t i = it->second;
rdubner's avatar
rdubner committed
453
        v_cob_fields[i].b_name = b_name_;
454 455 456 457 458 459 460
        v_cob_fields[i].offset = offset_;
    }

    void
    Dump() const
    {
        std::cout << "COB_FIELDS:" << std::endl;
rdubner's avatar
rdubner committed
461 462
        std::cout << std::setw(20) << "f_name" ;
        std::cout << std::setw(20) << "b_name";
463
        std::cout << std::setw(20) << "offset" ;
rdubner's avatar
rdubner committed
464 465
        std::cout << std::setw(20) << "size";
        std::cout << std::setw(20) << "a_name";
466 467 468
        std::cout << std::setw(20) << "program_id";
        std::cout << std::setw(20) << "cbl_name";
        std::cout << std::endl;
469

470
        for( V_COB_FIELDS::const_iterator it = v_cob_fields.begin();
471 472
                it!=v_cob_fields.end();
                it++) {
473
            COB_FIELD field = *it;
rdubner's avatar
rdubner committed
474 475
            std::cout << std::setw(20) << field.f_name ;
            std::cout << std::setw(20) << field.b_name;
476
            std::cout << std::setw(20) << field.offset ;
rdubner's avatar
rdubner committed
477 478
            std::cout << std::setw(20) << field.size;
            std::cout << std::setw(20) << field.a_name;
479 480 481 482 483
            std::cout << std::setw(20) << field.program_id;
            std::cout << std::setw(20) << field.cbl_name;
            std::cout << std::endl;
        }
        std::cout << std::endl;
484 485 486
    }
};

487 488
class COB_PROGRAM_LABELS;
class COB_PROGRAM_LABEL
489
{
490 491 492 493 494 495
private:
    char type;
    // P for PROGRAM-ID
    // E for ENTRY
    // S for SECTION
    // G for PARAGRAPH
496
    std::string source_file;
497 498 499 500 501 502 503
    int line_number;
    int sentence_number;
    std::string program;
    std::string entry;
    std::string section;
    std::string paragraph;

504 505 506 507 508 509 510 511 512
public:
    COB_PROGRAM_LABEL(char type_,
                      const std::string &source_file_,
                      int line_number_,
                      int sentence_number_,
                      const std::string &program_,
                      const std::string &entry_,
                      const std::string &section_,
                      const std::string &paragraph_)
513
    {
514 515 516 517 518 519 520 521
        type            = type_           ;
        source_file     = source_file_    ;
        line_number     = line_number_    ;
        sentence_number = sentence_number_;
        program         = program_        ;
        entry           = entry_          ;
        section         = section_        ;
        paragraph       = paragraph_      ;
522
    }
523 524

    friend COB_PROGRAM_LABELS;
525
};
526
typedef std::vector<COB_PROGRAM_LABEL>VCOB_PROGRAM_LABEL;
527

528
class COB_PROGRAM_LABELS
529
{
530 531
private:
    VCOB_PROGRAM_LABEL program_labels;
532 533

public:
534
    COB_PROGRAM_LABELS()
535 536
    {
    }
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    void
    AddEntry(char type,
             const std::string &source_file,
             int line_number,
             int sentence_number,
             const std::string &program,
             const std::string &entry,
             const std::string &section,
             const std::string &paragraph)
    {
        COB_PROGRAM_LABEL cpl(  type,
                                source_file,
                                line_number,
                                sentence_number,
                                program,
                                entry,
                                section,
                                paragraph);
        program_labels.push_back(cpl);
    }
    void FormatProgramInfo(std::stringstream &ss) const;
558

559 560
    void
    Dump() const
561
    {
562 563 564 565 566 567 568 569 570 571
        std::cout << "COB_PROGRAM_LABELS:\n";
        std::cout << std::setw( 5) << "t";
        std::cout << std::setw(15) << "source_file";
        std::cout << std::setw( 6) << "line";
        std::cout << std::setw(30) << "program";
        std::cout << std::setw(30) << "entry";
        std::cout << std::setw(30) << "section";
        std::cout << std::setw(30) << "paragraph";
        std::cout << std::endl;

572 573 574 575
        for( VCOB_PROGRAM_LABEL::const_iterator it=program_labels.begin();
                it!=program_labels.end();
                it++) {
            COB_PROGRAM_LABEL label = *it;
576 577 578 579 580 581 582 583 584 585
            std::cout << std::setw( 5) << label.type;
            std::cout << std::setw(15) << label.source_file;
            std::cout << std::setw( 6) << label.line_number;
            std::cout << std::setw(30) << label.program;
            std::cout << std::setw(30) << label.entry;
            std::cout << std::setw(30) << label.section;
            std::cout << std::setw(30) << label.paragraph;
            std::cout << std::endl;
        }
        std::cout << std::endl;
586 587 588
    }
};

589
class DATA_DESCRIPTIONS;
590 591 592 593
class DATA_DESCRIPTION
{
public:
    std::string program_id;
rdubner's avatar
rdubner committed
594
    std::string cobol_symbol;
595
    std::string storage_type;
rdubner's avatar
rdubner committed
596 597 598 599
    std::string b_name;
    int         offset;
    int         size;
    std::string f_name;
600 601 602 603 604
    std::string picture_string;

public:
    DATA_DESCRIPTION()
    {
rdubner's avatar
rdubner committed
605 606
        offset = 0;
        size = 0;
607
    }
608
    friend DATA_DESCRIPTIONS;
609 610 611
};
typedef std::vector<DATA_DESCRIPTION> VDATA_DESCRIPTION;

612
typedef std::map<std::string,size_t> M_VKEY;
613

614 615 616 617
class DATA_DESCRIPTIONS
{
private:
    VDATA_DESCRIPTION symbols;
618 619
    // We are going to key that table by (program-id, cbl_symbol,offset)
    M_VKEY symbols_key;
620

621
    std::map<std::string,size_t>location_of_c_symbol;
622 623

public:
rdubner's avatar
rdubner committed
624 625
    int
    size() const
626 627 628 629
    {
        return static_cast<int>(symbols.size());
    }

rdubner's avatar
rdubner committed
630
    const DATA_DESCRIPTION &
631
    operator[](size_t n) const
632 633 634 635
    {
        return symbols[n];
    }

rdubner's avatar
rdubner committed
636 637
    int
    IndexOfSymbol(const std::string &symbol) const
638
    {
639
        std::map<std::string,size_t>::const_iterator it =
640 641
            location_of_c_symbol.find(symbol);
        if(it == location_of_c_symbol.end()) {
642 643 644 645 646
            return -1;
        }
        return static_cast<int>(it->second);
    }

rdubner's avatar
rdubner committed
647
    std::string
648
    MakeVKey(std::string const &program_id, std::string const &c_symbol,int offset) const
649 650 651
    {
        char ach[20];
        sprintf(ach,"%d",offset);
652
        return program_id + "|" + c_symbol + "|" + ach;
653 654 655 656
    }

    void
    DsInsert(const DATA_DESCRIPTION &ds )
657
    {
rdubner's avatar
rdubner committed
658
        symbols_key[MakeVKey(ds.program_id,ds.cobol_symbol,ds.offset)] = symbols.size();
659 660 661 662
        symbols.push_back(ds);
    }

    bool
rdubner's avatar
rdubner committed
663
    IsInDs(std::string const &program_id, std::string const &cobol_symbol,int offset) const
664
    {
rdubner's avatar
rdubner committed
665
        std::string dskey=MakeVKey(program_id,cobol_symbol,offset);
666 667 668
        M_VKEY::const_iterator it = symbols_key.find(dskey);
        return it != symbols_key.end();
    }
rdubner's avatar
rdubner committed
669

670
    size_t
671
    GetIndex(std::string const &program_id, std::string const &c_symbol,int offset) const
672 673
    {
        size_t retval = (size_t)(-1);
674
        std::string dskey=MakeVKey(program_id,c_symbol,offset);
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
        M_VKEY::const_iterator it = symbols_key.find(dskey);
        if(it != symbols_key.end()) {
            retval = it->second;
        }
        return retval;
    }

    void Dump() const;

    void Flatten(const COB_FIELDS &cob_fields,
                 const COB_FIELD_ATTRIBUTES &cob_field_attributes,
                 const COB_PIC_SYMBOLS &cob_pic_symbols,
                 const COB_DATA &cob_data
                );

690 691
};

692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
void ScanAllDotHFiles(const std::string &path,
                      const std::string &fname,
                      COB_PIC_SYMBOLS &cob_pic_symbols,
                      COB_DATA &cob_data,
                      COB_FIELD_ATTRIBUTES &cob_field_attributes,
                      COB_FIELDS &cob_fields
                     );
void ScanForLinkage(std::ifstream &ifs,
                    const std::string &current_c_source,
                    COB_PROGRAM_LABELS &program_labels,
                    COB_DATA &cob_data,
                    COB_FIELDS &cob_fields
                   );


707 708 709 710 711
#ifdef NEEDED_TO_DEFINE_EQ
#undef EQ
#undef AND
#undef OR
#endif