#include "lclintMacros.nf"#include "llbasic.h"#include "gram.h"#include "lclscan.h"#include "scanline.h"#include "lclscanline.h"#include "lcltokentable.h"#include "lclsyntable.h"Go to the source code of this file.
Defines | |
| #define | CHARSIZE 256 |
| #define | LCLMOVECHAR() |
| #define | LOOKAHEADCHAR() (*currentLine) |
| #define | LOOKAHEADTWICECHAR() (*(currentLine + 1)) |
| #define | MAXCHAR 512 |
| #define | FIRSTRESERVEDNAME "?" |
Enumerations | |
| enum | StartCharType { STARTCNUM, STARTCNUMDOT, STARTCSTR, STARTCCHAR, STARTWIDE, STARTSLASH, STARTOTHER } |
Functions | |
| void | LCLScanLine (char *line) |
| ltoken | LCLScanEofToken (void) |
| void | LCLReportEolTokens (bool setting) |
| void | LCLScanLineInit (void) |
| void | LCLScanLineReset (void) |
| void | LCLScanLineCleanup (void) |
| bool | LCLIsEndComment (char c) |
| charCode | LCLScanCharClass (char c) |
| void | LCLSetCharClass (char c, charCode cod) |
| void | LCLSetEndCommentChar (char c, bool flag) |
|
|
Definition at line 62 of file lclscanline.c. |
|
|
Definition at line 84 of file lclscanline.c. |
|
|
Initializer: \
do { *bufPtr++ = currentChar; currentChar = *currentLine++; \
colNumber++; } while (FALSE)Definition at line 65 of file lclscanline.c. Referenced by LCLScanLine(). |
|
|
Definition at line 70 of file lclscanline.c. Referenced by LCLScanLine(). |
|
|
Definition at line 73 of file lclscanline.c. Referenced by LCLScanLine(). |
|
|
Definition at line 76 of file lclscanline.c. |
|
|
Definition at line 91 of file lclscanline.c. 00092 {
00093 STARTCNUM, /* First character of a C number. */
00094 STARTCNUMDOT, /* "." only starts a C number if digit follows*/
00095 STARTCSTR, /* First character of a C string. */
00096 STARTCCHAR, /* First character of a C character. */
00097 STARTWIDE, /* slash L starts both string and character. */
00098 STARTSLASH, /* "/" starts caret, comment comment, operator */
00099 STARTOTHER /* Everything else. */
00100 }
|
|
|
Definition at line 1925 of file lclscanline.c. Referenced by LCLScanLine(). 01926 {
01927 return LCLcharClass[(int)(c)].endCommentChar;
01928 }
|
|
|
Definition at line 1704 of file lclscanline.c. Referenced by LCLProcessInitFileInit(). 01705 {
01706 reportEOL = setting;
01707 }
|
|
|
Definition at line 1930 of file lclscanline.c. Referenced by LCLScanLine(), and ltoken_isSingleChar(). 01931 {
01932 return LCLcharClass[(int)(c)].code;
01933 }
|
|
|
Definition at line 1687 of file lclscanline.c. Referenced by LCLScanNextToken(). 01688 {
01689 ltoken t = LCLInsertToken (LEOFTOKEN, lsymbol_fromChars ("E O F"), 0, TRUE);
01690
01691 if (inComment)
01692 {
01693 lclerror (commentTok, cstring_makeLiteral ("Unterminated comment"));
01694 }
01695
01696 ltoken_setCol (t, colNumber);
01697 ltoken_setLine (t, tsource_thisLineNumber (LCLScanSource ()));
01698 ltoken_setFileName (t, tsource_fileName (LCLScanSource ()));
01699
01700 return t;
01701 }
|
|
|
Definition at line 1424 of file lclscanline.c. Referenced by LCLScanNextToken(). 01425 {
01426 ltoken newToken;
01427 lsymbol CCommentSym = lsymbol_fromChars ("/*");
01428 size_t linelength = strlen (line);
01429 static bool inSpecComment = FALSE;
01430
01431 line[(int)linelength] = '\n';
01432
01433 currentLine = line;
01434 currentChar = *currentLine++;
01435 context_processedSpecLine ();
01436
01437 incLine ();
01438 colNumber = 1;
01439
01440 if (inComment)
01441 {
01442 ScanCComment ();
01443
01444 if (reportComments)
01445 {
01446 *bufPtr = '\0';
01447 newToken = ltoken_createRaw (simpleId, lsymbol_fromChars (&tokenBuffer[0]));
01448 LCLScanFreshToken (newToken);
01449 }
01450 }
01451
01452 if (inSpecComment)
01453 {
01454 if (currentChar == '*' &&
01455 LOOKAHEADCHAR () == '/')
01456 {
01457 LCLMOVECHAR ();
01458 LCLMOVECHAR ();
01459 inSpecComment = FALSE;
01460 }
01461 }
01462
01463 /*@+loopexec@*/
01464 for (;;)
01465 {
01466 if (inSpecComment && currentChar == '*' && LOOKAHEADCHAR () == '/')
01467 {
01468 LCLMOVECHAR ();
01469 LCLMOVECHAR ();
01470 inSpecComment = FALSE;
01471 }
01472
01473 bufPtr = &tokenBuffer[0];
01474 startCol = colNumber;
01475
01476
01477 /*@-loopswitchbreak@*/
01478 switch (startClass[(int)currentChar])
01479 {
01480 case STARTCNUM:
01481 ScanCNumber ();
01482 break;
01483
01484 case STARTCNUMDOT:
01485 if (isDigit[(int) LOOKAHEADCHAR ()])
01486 {
01487 ScanCNumber ();
01488 }
01489 else
01490 {
01491 ScanOther ();
01492 }
01493 break;
01494
01495 case STARTCSTR:
01496 ScanCString ();
01497 break;
01498
01499 case STARTCCHAR:
01500 if (nextCanBeCharLiteral (prevTokenCode))
01501 {
01502 ScanCChar ();
01503 }
01504 else
01505 {
01506 ScanOther ();
01507 }
01508 break;
01509
01510 case STARTWIDE:
01511 if (LOOKAHEADCHAR () == 'L' && LOOKAHEADTWICECHAR () == '\"')
01512 {
01513 ScanCString ();
01514 }
01515 else if (LOOKAHEADCHAR () == 'L' && LOOKAHEADTWICECHAR () == '\'')
01516 {
01517 ScanCChar ();
01518 }
01519 else
01520 {
01521 ScanOther ();
01522 }
01523 break;
01524
01525 case STARTSLASH:
01526 if (LOOKAHEADCHAR () == '*')
01527 {
01528 LCLMOVECHAR ();
01529 LCLMOVECHAR ();
01530
01531 if (currentChar == '@')
01532 {
01533 char *s = mstring_createEmpty ();
01534
01535 LCLMOVECHAR ();
01536
01537 while (currentChar != '\0' && currentChar != ' '
01538 && currentChar != '*' && currentChar != '\t' &&
01539 currentChar != '\n')
01540 {
01541 s = mstring_append (s, currentChar);
01542 LCLMOVECHAR ();
01543 }
01544
01545 if (mstring_equal (s, "alt"))
01546 {
01547 tokenCode = LLT_VERTICALBAR;
01548 tokenSym = lsymbol_fromChars ("|");
01549 inSpecComment = TRUE;
01550 }
01551 else
01552 {
01553 ScanCComment ();
01554 tokenCode = commentSym;
01555 tokenSym = CCommentSym;
01556 }
01557
01558 sfree (s);
01559 break;
01560 }
01561 else
01562 {
01563 ScanCComment ();
01564 tokenCode = commentSym;
01565 tokenSym = CCommentSym;
01566 break;
01567 }
01568 }
01569 else
01570 {
01571 ScanOther ();
01572 } break;
01573
01574 case STARTOTHER:
01575 ScanOther ();
01576 break;
01577
01578 default:
01579 llcontbuglit ("LCLScanLine: bad case");
01580 break;
01581
01582 }
01583 /*@=loopswitchbreak@*/
01584
01585 /*
01586 ** Above code only "guessed" at token type. Insert it into the
01587 ** TokenTable. If the token already exists, it is returned as
01588 ** previously defined. If it does not exist, it is inserted as the
01589 ** token code computed above.
01590 */
01591
01592 newToken = LCLInsertToken (tokenCode, tokenSym, lsymbol_undefined, FALSE);
01593
01594
01595 if (LCLIsSyn (ltoken_getText (newToken)))
01596 {
01597 /*
01598 ** Token is a synonym. Get the actual token and set the raw
01599 ** text to the synonym name.
01600 */
01601
01602 newToken = ltoken_copy (LCLGetTokenForSyn (ltoken_getText (newToken)));
01603
01604 ltoken_setRawText (newToken, tokenSym);
01605 }
01606 else
01607 {
01608 newToken = ltoken_copy (newToken);
01609 }
01610
01611 ltoken_setCol (newToken, startCol);
01612 ltoken_setLine (newToken, tsource_thisLineNumber (LCLScanSource ()));
01613 ltoken_setFileName (newToken, tsource_fileName (LCLScanSource ()));
01614
01615 if (ltoken_getCode (newToken) == commentSym)
01616 {
01617 if (tokenSym == CCommentSym)
01618 { /* C-style comment */
01619 ltoken_free (commentTok);
01620 commentTok = ltoken_copy (newToken);
01621
01622 if (!inComment && reportComments)
01623 {
01624 *bufPtr = '\0';
01625 ltoken_setRawText (newToken,
01626 lsymbol_fromChars (&tokenBuffer[0]));
01627 LCLScanFreshToken (newToken);
01628 }
01629 else
01630 {
01631 ltoken_free (newToken);
01632 }
01633 }
01634 else
01635 { /* LSL-style comment */
01636 bufPtr = &tokenBuffer[0];
01637 while (!LCLIsEndComment (currentChar))
01638 {
01639 LCLMOVECHAR ();
01640 }
01641 if (LCLScanCharClass (currentChar) != CHC_NULL)
01642 {
01643 /* Not EOL character. Toss it out. */
01644 LCLMOVECHAR ();
01645 }
01646
01647 if (reportComments)
01648 {
01649 *bufPtr = '\0';
01650 ltoken_setRawText (newToken,
01651 lsymbol_fromChars (&tokenBuffer[0]));
01652 LCLScanFreshToken (newToken);
01653 }
01654 else
01655 {
01656 ltoken_free (newToken);
01657 }
01658 }
01659 }
01660 else if (ltoken_getCode (newToken) == LLT_EOL)
01661 {
01662 if (reportEOL)
01663 {
01664 LCLScanFreshToken (newToken);
01665 }
01666 else
01667 {
01668 ltoken_free (newToken);
01669 }
01670
01671 line[(int) linelength] = '\0';
01672 return;
01673 }
01674 else if (ltoken_getCode (newToken) != LLT_WHITESPACE)
01675 {
01676 prevTokenCode = ltoken_getCode (newToken);
01677 LCLScanFreshToken (newToken);
01678 }
01679 else
01680 {
01681 ltoken_free (newToken);
01682 }
01683 } /*@=loopexec@*/
01684 }
|
|
|
Definition at line 1921 of file lclscanline.c. 01922 {
01923 }
|
|
|
Definition at line 1721 of file lclscanline.c. 01722 {
01723 int i;
01724
01725 setCodePoint ();
01726 reportEOL = FALSE;
01727 reportComments = FALSE;
01728
01729 for (i = 0; i <= LASTCHAR; i++)
01730 {
01731 LCLcharClass[i] = charClassDef[i];
01732 }
01733
01734 setCodePoint ();
01735
01736 /*
01737 ** Make sure first postion is never used because use the 0th index to
01738 ** mean empty.
01739 */
01740
01741 firstReserved = lsymbol_fromChars (FIRSTRESERVEDNAME);
01742 setCodePoint ();
01743
01744 /* Predefined LSL Tokens */
01745
01746 ltoken_forall = LCLReserveToken (quantifierSym, "\\forall");
01747 setCodePoint ();
01748 ltoken_exists = LCLReserveToken (quantifierSym, "\\exists");
01749 ltoken_implies = LCLReserveToken (logicalOp, "\\implies");
01750 ltoken_eqsep = LCLReserveToken (eqSepSym, "\\eqsep");
01751 ltoken_select = LCLReserveToken (selectSym, "\\select");
01752 ltoken_open = LCLReserveToken (openSym, "\\open");
01753 ltoken_sep = LCLReserveToken (sepSym, "\\,");
01754 ltoken_close = LCLReserveToken (closeSym, "\\close");
01755 ltoken_id = LCLReserveToken (simpleId, "\\:");
01756 ltoken_arrow = LCLReserveToken (mapSym, "\\arrow");
01757 ltoken_marker = LCLReserveToken (markerSym, "\\marker");
01758 ltoken_pre = LCLReserveToken (preSym, "\\pre");
01759 ltoken_post = LCLReserveToken (postSym, "\\post");
01760 ltoken_comment = LCLReserveToken (commentSym, "\\comment");
01761 ltoken_any = LCLReserveToken (anySym, "\\any");
01762
01763 ltoken_result = LCLReserveToken (LLT_RESULT, "result");
01764 ltoken_typename = LCLReserveToken (LLT_TYPEDEF_NAME, "TYPEDEF_NAME");
01765 ltoken_setIdType (ltoken_typename, SID_TYPE);
01766
01767 /*
01768 ** Not context_getBoolName () --- "bool" is built in to LCL.
01769 ** This is bogus, but necessary for a lot of old lcl files.
01770 */
01771
01772 ltoken_bool = LCLReserveToken (LLT_TYPEDEF_NAME, "bool");
01773
01774 ltoken_lbracked = LCLReserveToken (LLT_LBRACKET, "[");
01775 ltoken_rbracket = LCLReserveToken (LLT_RBRACKET, "]");
01776
01777 (void) LCLReserveToken (LLT_COLON, ":");
01778 (void) LCLReserveToken (LLT_COMMA, ",");
01779
01780 (void) LCLReserveToken (LLT_EQUALS, "=");
01781 (void) LCLReserveToken (LLT_LBRACE, "{");
01782 (void) LCLReserveToken (LLT_LPAR, "(");
01783 (void) LCLReserveToken (LLT_RBRACE, "}");
01784 (void) LCLReserveToken (LLT_RPAR, ")");
01785 (void) LCLReserveToken (LLT_SEMI, ";");
01786 (void) LCLReserveToken (LLT_VERTICALBAR, "|");
01787
01788 (void) LCLReserveToken (LLT_MULOP, "*");
01789
01790 (void) LCLReserveToken (LLT_WHITESPACE, " ");
01791 (void) LCLReserveToken (LLT_WHITESPACE, "\t");
01792 (void) LCLReserveToken (LLT_WHITESPACE, "\f");
01793 (void) LCLReserveToken (LLT_WHITESPACE, "\n");
01794
01795 (void) LCLReserveToken (LEOFTOKEN, "E O F");
01796 (void) LCLReserveToken (LLT_EOL, "E O L");
01797
01798 /* LSL Keywords */
01799 ltoken_and = LCLReserveToken (logicalOp, "\\and");
01800 ltoken_or = LCLReserveToken (logicalOp, "\\or");
01801
01802 ltoken_equals = LCLReserveToken (equationSym, "\\equals");
01803
01804 ltoken_eq = LCLReserveToken (eqOp, "\\eq");
01805 ltoken_neq = LCLReserveToken (eqOp, "\\neq");
01806
01807 ltoken_not = LCLReserveToken (simpleOp, "\\not");
01808 ltoken_true = LCLReserveToken (simpleId, "true");
01809 ltoken_false = LCLReserveToken (simpleId, "false");
01810
01811 /* LCL Keywords */
01812 (void) LCLReserveToken (LLT_ALL, "all");
01813 (void) LCLReserveToken (LLT_ANYTHING, "anything");
01814 (void) LCLReserveToken (LLT_BE, "be");
01815 (void) LCLReserveToken (LLT_CONSTANT, "constant");
01816 (void) LCLReserveToken (LLT_CHECKS, "checks");
01817 (void) LCLReserveToken (LLT_ELSE, "else");
01818 (void) LCLReserveToken (LLT_ENSURES, "ensures");
01819 (void) LCLReserveToken (LLT_FOR, "for");
01820 (void) LCLReserveToken (LLT_IF, "if");
01821 (void) LCLReserveToken (LLT_IMMUTABLE, "immutable");
01822 (void) LCLReserveToken (LLT_OBJ, "obj");
01823 (void) LCLReserveToken (LLT_OUT, "out");
01824 (void) LCLReserveToken (LLT_ITER, "iter");
01825 (void) LCLReserveToken (LLT_YIELD, "yield");
01826 (void) LCLReserveToken (LLT_PARTIAL, "partial");
01827 (void) LCLReserveToken (LLT_ONLY, "only");
01828 (void) LCLReserveToken (LLT_UNDEF, "undef");
01829 (void) LCLReserveToken (LLT_KILLED, "killed");
01830 (void) LCLReserveToken (LLT_OWNED, "owned");
01831 (void) LCLReserveToken (LLT_DEPENDENT, "dependent");
01832 (void) LCLReserveToken (LLT_PARTIAL, "partial");
01833 (void) LCLReserveToken (LLT_RELDEF, "reldef");
01834 (void) LCLReserveToken (LLT_KEEP, "keep");
01835 (void) LCLReserveToken (LLT_KEPT, "kept");
01836 (void) LCLReserveToken (LLT_TEMP, "temp");
01837 (void) LCLReserveToken (LLT_SHARED, "shared");
01838 (void) LCLReserveToken (LLT_RELNULL, "relnull");
01839 (void) LCLReserveToken (LLT_RELDEF, "reldef");
01840 (void) LCLReserveToken (LLT_CHECKED, "checked");
01841 (void) LCLReserveToken (LLT_UNCHECKED, "unchecked");
01842 (void) LCLReserveToken (LLT_CHECKEDSTRICT, "checkedstrict");
01843 (void) LCLReserveToken (LLT_CHECKMOD, "checkmod");
01844 (void) LCLReserveToken (LLT_TRUENULL, "truenull");
01845 (void) LCLReserveToken (LLT_FALSENULL, "falsenull");
01846 (void) LCLReserveToken (LLT_LNULL, "null");
01847 (void) LCLReserveToken (LLT_LNOTNULL, "notnull");
01848 (void) LCLReserveToken (LLT_RETURNED, "returned");
01849 (void) LCLReserveToken (LLT_OBSERVER, "observer");
01850 (void) LCLReserveToken (LLT_EXPOSED, "exposed");
01851 (void) LCLReserveToken (LLT_REFCOUNTED, "refcounted");
01852 (void) LCLReserveToken (LLT_REFS, "refs");
01853 (void) LCLReserveToken (LLT_NEWREF, "newref");
01854 (void) LCLReserveToken (LLT_TEMPREF, "tempref");
01855 (void) LCLReserveToken (LLT_KILLREF, "killref");
01856 (void) LCLReserveToken (LLT_EXITS, "exits");
01857 (void) LCLReserveToken (LLT_MAYEXIT, "mayexit");
01858 (void) LCLReserveToken (LLT_TRUEEXIT, "trueexit");
01859 (void) LCLReserveToken (LLT_FALSEEXIT, "falseexit");
01860 (void) LCLReserveToken (LLT_NEVEREXIT, "neverexit");
01861 (void) LCLReserveToken (LLT_SEF, "sef");
01862 (void) LCLReserveToken (LLT_UNUSED, "unused");
01863 (void) LCLReserveToken (LLT_UNIQUE, "unique");
01864 (void) LCLReserveToken (LLT_IMPORTS, "imports");
01865 (void) LCLReserveToken (LLT_CONSTRAINT, "constraint");
01866 (void) LCLReserveToken (LLT_LET, "let");
01867 (void) LCLReserveToken (LLT_MODIFIES, "modifies");
01868 (void) LCLReserveToken (LLT_CLAIMS, "claims");
01869 (void) LCLReserveToken (LLT_BODY, "body");
01870 (void) LCLReserveToken (LLT_MUTABLE, "mutable");
01871 (void) LCLReserveToken (LLT_FRESH, "fresh");
01872 (void) LCLReserveToken (LLT_NOTHING, "nothing");
01873 (void) LCLReserveToken (LLT_INTERNAL, "internalState");
01874 (void) LCLReserveToken (LLT_FILESYS, "fileSystem");
01875 (void) LCLReserveToken (LLT_PRIVATE, "private");
01876 (void) LCLReserveToken (LLT_SPEC, "spec");
01877 (void) LCLReserveToken (LLT_REQUIRES, "requires");
01878 (void) LCLReserveToken (LLT_SIZEOF, "sizeof");
01879 (void) LCLReserveToken (LLT_TAGGEDUNION, "taggedunion");
01880 (void) LCLReserveToken (LLT_THEN, "then");
01881 (void) LCLReserveToken (LLT_TYPE, "type");
01882 (void) LCLReserveToken (LLT_TYPEDEF, "typedef");
01883 (void) LCLReserveToken (LLT_UNCHANGED, "unchanged");
01884 (void) LCLReserveToken (LLT_USES, "uses");
01885 (void) LCLReserveToken (LLT_PRINTFLIKE, "printflike");
01886 (void) LCLReserveToken (LLT_SCANFLIKE, "scanflike");
01887 (void) LCLReserveToken (LLT_MESSAGELIKE, "messagelike");
01888
01889 /* LCL C Keywords */
01890 (void) LCLReserveToken (LLT_CHAR, "char");
01891 (void) LCLReserveToken (LLT_CONST, "const");
01892 (void) LCLReserveToken (LLT_DOUBLE, "double");
01893 (void) LCLReserveToken (LLT_ENUM, "enum");
01894
01895 /* comment out so we can add in lclinit.lci: synonym double float */
01896 /* LCLReserveToken (LLT_FLOAT, "float"); */
01897 /* But we need to make the scanner parse "float" not as a simpleId, but
01898 as a TYPEDEF_NAME. This is done later in abstract_init */
01899
01900 (void) LCLReserveToken (LLT_INT, "int");
01901 (void) LCLReserveToken (LLT_LONG, "long");
01902 (void) LCLReserveToken (LLT_SHORT, "short");
01903 (void) LCLReserveToken (LLT_STRUCT, "struct");
01904 (void) LCLReserveToken (LLT_SIGNED, "signed");
01905 (void) LCLReserveToken (LLT_UNION, "union");
01906 (void) LCLReserveToken (LLT_UNKNOWN, "__unknown");
01907 (void) LCLReserveToken (LLT_UNSIGNED, "unsigned");
01908 (void) LCLReserveToken (LLT_VOID, "void");
01909 (void) LCLReserveToken (LLT_VOLATILE, "volatile");
01910 setCodePoint ();
01911 }
|
|
|
Definition at line 1914 of file lclscanline.c. 01915 {
01916 inComment = FALSE;
01917 prevTokenCode = LLT_LPAR; /* Presume first ' starts literal */
01918 }
|
|
|
Definition at line 1935 of file lclscanline.c. 01936 {
01937 LCLcharClass[(int)(c)].code = (cod);
01938 }
|
|
|
Definition at line 1940 of file lclscanline.c. 01941 {
01942 LCLcharClass[(int)(c)].endCommentChar = flag;
01943 }
|
1.2.3 written by Dimitri van Heesch,
© 1997-2000