📄 cpp.ll
字号:
/* cpp.ll Copyright (c) 1996 Roland Wunderling, Malte Zoeckler Copyright (c) 1998 Michael Meeks Copyright (c) 1999-2001 Dragos Acostachioaie This file is part of DOC++. DOC++ is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the license, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/%{#include <assert.h>#include <ctype.h>#include <iostream.h>#include <stdarg.h>#include <stdio.h>#include "doc.h"static const char* inputString;static int inputPosition;static int lastCContext;static int protection = PUBL;static int curlyBracketCount = 0;static int innerCurlyCount = 0;static int skipCurlyStart = 0;static int roundBracketCount = 0;static int skipReturn = 0;static int sharpCount = 0;static Entry* current_root = 0;static Entry* global_root = 0;static Entry* current = 0;static Entry* last = 0; // For handling trailing commentsstatic int argumentStartPos;McDArray<namespace_entry *> namespace_table;static int yyLineNr = 0;static char yyFileName[264];extern void addNamespace(Entry* entry);void msg(const char *__fmt, ...){ char s[1024]; va_list argptr; va_start(argptr, __fmt); vsprintf(s, __fmt, argptr); va_end(argptr); fprintf(stderr, "%s(%d): %s\n", yyFileName, yyLineNr, s);}#ifdef DEBUGvoid debug(const char *__fmt, ...){ char s[1024]; if(verb) { va_list argptr; va_start(argptr, __fmt); vsprintf(s, __fmt, argptr); va_end(argptr); printf("%s(%d): %s\n", yyFileName, yyLineNr, s); }}#endifstatic void lineCount(){ const char *c; for(c = yytext; *c; ++c) yyLineNr += (*c == '\n');}static void addType(Entry *current){ if(current->type.length() > 0 && current->type[current->type.length() - 1] == '*' && current->name[0] == '*') return; if(current->type.length()) current->type += ' '; current->type += current->name; current->name.clear(); current->type += current->args; current->args.clear(); current->startLine = yyLineNr;}static char nonewline(char c){ return (c == '\n') ? ' ' : c;}#undef YY_INPUT#define YY_INPUT(buf, result, max_size) result = yyread(buf, max_size);static int yyread(char *buf, int max_size){ int c = 0; while(c < max_size && inputString[inputPosition]) { *buf = inputString[inputPosition++]; c++; buf++; } return c;}static int addParamDoc(){ if(current->doc.length() == 0) return 0; char *start = current->args; start += argumentStartPos; argumentStartPos = current->args.length(); char *end = start; while(*end != '\0' && *end != '=') end++; if(start == end) return 0; do { end--; } while(end != start && (isspace(*end) || *end == ',' || *end == ')')); char *identifier = end; while(start != identifier && (isalnum(*identifier) || *identifier == '_')) identifier--; if(identifier == end) return 0; current->doc += "\n@param "; while(identifier != end) current->doc += *++identifier; current->doc += ' '; return 1;}%}%x Cxx_Memo%x SubDoc%x SubDocComment%x SubDocCppComment%x Namespace%x UsingNamespace%x Doc%x VerbDoc%x Define%x DefineEnd%x DefineEnded%x StorageModifier%x File%x ClassName%x IdlUnion%x IdlSwitch%x IdlCase%x Bases%x NextSemi%x FindMembers%x FindMembersSuffix%x GrabSuffixMemo%x FindMembersName%x Function%x Operator%x Throws%x Union%x Friend%x Array%x Round%x Curly%x SkipCurly%x SkipInits%x SkipCPP%x SkipSemiOrCurly%x SkipSemiAndCurly%x Sharp%x Comment%x SkipComment%x SkipCxxComment%x Param_Doc%x Param_CxxDoc%%<*>\x06[^\x06]*\x06 { int i; for(i = 0; yytext[i + 1] != 6; i++) yyFileName[i] = yytext[i + 1]; yyFileName[i] = 0; }<*>"'"[{}]"'" { }<*>^[ \t]*#(if|ifdef|ifndef|elif).*\n { // kill `#if', `#ifdef', `#ifndef', `#elif' }<*>^[ \t]*#(else|endif).*\n { // kill `#else', `#endif' }^[ \t]*"$"[ \t]*"$" { // kill RCS keywords }<NextSemi>"{" { // Array inits skipReturn = NextSemi; skipCurlyStart = curlyBracketCount; BEGIN(SkipCurly); }<NextSemi>[;,] { BEGIN(FindMembersSuffix); }<FindMembers>[ \t]*"public"[ \t\n]*":"[ \t\n]* { current->protection = protection = PUBL; lineCount(); }<FindMembers>[ \t]*"protected"[ \t\n]*":"[ \t\n]* { current->protection = protection = PROT; lineCount(); }<FindMembers>[ \t]*"private"[ \t\n]*":"[ \t\n]* { current->protection = protection = PRIV; lineCount(); }<FindMembers>[ \t]*"namespace"[ \t\n]+ { current->section = NAMESPACE_SEC; current->type = "namespace"; lineCount(); BEGIN(Namespace); }<FindMembers>[ \t]*"using"[ \t\n]+"namespace"[ \t\n]+ { lineCount(); BEGIN(UsingNamespace); }<FindMembers>[ \t]*"typedef"[ \t\n]+"class"[ \t\n]+ { current->section = TYPEDEF_SEC; current->type = "typedef class"; current->name.clear(); lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"typedef"[ \t\n]+"struct"[ \t\n]+ { current->section = TYPEDEF_SEC; current->type = "typedef struct"; current->name.clear(); lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"typedef"[ \t\n]+"enum"[ \t\n]+ { current->section = TYPEDEF_SEC; current->type = "typedef enum"; current->name.clear(); lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"typedef"[ \t\n]+"union"[ \t\n]+ { current->section = TYPEDEF_SEC; current->type = "typedef union"; current->name.clear(); lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"typedef"[ \t\n]+ { current->section = TYPEDEF_SEC; current->type = "typedef"; current->name.clear(); lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"class"[ \t\n]+ { current->section = CLASS_SEC; addType(current); current->type += "class"; lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"interface"[ \t\n]+ { // IDL mode current->section = INTERFACE_SEC; addType(current); current->type += "interface"; lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"struct"[ \t\n]+ { current->section = UNION_SEC; addType(current); current->type += "struct"; lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"exception"[ \t\n]+ { // IDL mode current->section = UNION_SEC; addType(current); current->type += "exception"; lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"enum"[ \t\n]+ { current->section = UNION_SEC; addType(current); current->type += "enum"; lineCount(); BEGIN(ClassName); }<FindMembers>[ \t]*"union"[ \t\n]+ { current->section = UNION_SEC; addType(current); current->type += "union"; lineCount(); if(language == LANG_IDL) BEGIN(IdlUnion); else BEGIN(ClassName); }<FindMembers>[\t]*"case"[ \t\n]+ { // IDL mode current->section = UNION_SEC; addType(current); current->type += "case "; lineCount(); BEGIN(IdlCase); }<IdlCase>[a-z_A-Z~.0-9]+ { current->type += yytext; }<IdlCase>":"[ \t\n]+ { current->type += ": "; BEGIN(FindMembers); }<FindMembers>[ \t]*"//$$filename"[ \t]+ { // search for file name marker inserted // in `readfiles.ll' BEGIN(File); }<File>.* { // found a file name: now use it as the // current file name strcpy(yyFileName, yytext); }<File>\n { BEGIN(FindMembers); }<FindMembers>[ \t]*"extern \"C\""[ \t\n]+ { current->clear(); BEGIN(FindMembers); }<FindMembers>[ \t]*"friend"[ \t\n]+ { BEGIN(Friend); }<FindMembers>[ \t]*"inline"[ \t\n]+ { current->type += "inline "; }<FindMembers>[ \t]*"static"[ \t\n]+ { current->type += "static "; }<FindMembers>[ \t]*"volatile"[ \t\n]+ { current->type += "volatile "; }<FindMembers>[ \t]*"__cdecl"[ \t\n]+ { current->type += "__cdecl "; }<FindMembers>[ \t]*"ILVCALLBACK"[ \t\n]+ { current->type += "ILVCALLBACK "; }<FindMembers>[ \t]*"virtual"[ \t\n]+ { current->type += "virtual "; }<FindMembers>[ \t]*"LIBRARY"[ \t\n]+ {// PK: This one I simply need in doc++.// I have too many projects using this macro as a storage type modifier current->type += "LIBRARY "; }<FindMembers>[ \t]*"WINAPI"[ \t\n]+ {// WINAPI storage type modifier is now used instead of now obsolete __pascal,// __fortran and __syscall calling conventions current->type += "WINAPI "; }<FindMembers>[ \t]*"__declspec("[ \t\n]* {// Microsoft compiler specific: declarator current->type += "__declspec("; BEGIN(StorageModifier); }<StorageModifier>[ \t]*"dllexport)"[ \t\n]* {// Microsoft compiler specific: DLL export symbol current->type += "dllexport) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"dllimport)"[ \t\n]* {// Microsoft compiler specific: DLL import symbol current->type += "dllimport) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"thread)"[ \t\n]* {// Microsoft compiler specific: thread local storage in multithreading// environment current->type += "thread) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"naked)"[ \t\n]* {// Microsoft compiler specific: naked function without prolog and epilog code current->type += "naked) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"noreturn)"[ \t\n]* {// Microsoft compiler specific: prevents compiler to expect return values in// all return branches (error handlers) current->type += "noreturn) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"novtable)"[ \t\n]* {// Microsoft compiler specific: for pure class interfaces, which are never// instantiated on their own (saves plenty of space) current->type += "novtable) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"selectany)"[ \t\n]* {// Microsoft compiler specific: hint for linker to eliminate COMDAT current->type += "selectany) "; BEGIN(FindMembers); }<StorageModifier>[ \t]*"nothrow)"[ \t\n]* {// Microsoft compiler specific: eliminates lifetime tracking for unwindable// objects current->type += "nothrow) "; BEGIN(FindMembers); }<FindMembers>"operator"/[^a-z_A-Z0-9] { addType(current); current->name = yytext; BEGIN(Operator); }<Operator>[ \t\n]*"()"?[^(]* { current->name += yytext; BEGIN(FindMembersName); }<FindMembers,FindMembersName>[ \t]*":"[ \t]*[0-9]+[ \t]*/";" { // kill obscure bit-width stuff }<FindMembers>[ \t]*::[ \t]* { // Must append to name but if previous // text is current classname discard it. if(current->name == current_root->name) current->name.clear(); else current->name += "::"; BEGIN(FindMembersName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -