comparison dmd/doc.c @ 875:330f999ade44

Merged DMD 1.038
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 06 Jan 2009 16:33:51 +0100
parents cbd6c8073a32
children 27a379f288bf
comparison
equal deleted inserted replaced
874:2ddee23bd70e 875:330f999ade44
45 #include "doc.h" 45 #include "doc.h"
46 #include "mtype.h" 46 #include "mtype.h"
47 47
48 struct Escape 48 struct Escape
49 { 49 {
50 char *strings[256]; 50 const char *strings[256];
51 51
52 static char *escapeChar(unsigned c); 52 static const char *escapeChar(unsigned c);
53 }; 53 };
54 54
55 struct Section 55 struct Section
56 { 56 {
57 unsigned char *name; 57 unsigned char *name;
94 void parseSections(unsigned char *comment); 94 void parseSections(unsigned char *comment);
95 void writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf); 95 void writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf);
96 }; 96 };
97 97
98 98
99 int cmp(char *stringz, void *s, size_t slen); 99 int cmp(const char *stringz, void *s, size_t slen);
100 int icmp(char *stringz, void *s, size_t slen); 100 int icmp(const char *stringz, void *s, size_t slen);
101 int isDitto(unsigned char *comment); 101 int isDitto(unsigned char *comment);
102 unsigned char *skipwhitespace(unsigned char *p); 102 unsigned char *skipwhitespace(unsigned char *p);
103 unsigned skiptoident(OutBuffer *buf, unsigned i); 103 unsigned skiptoident(OutBuffer *buf, unsigned i);
104 unsigned skippastident(OutBuffer *buf, unsigned i); 104 unsigned skippastident(OutBuffer *buf, unsigned i);
105 unsigned skippastURL(OutBuffer *buf, unsigned i); 105 unsigned skippastURL(OutBuffer *buf, unsigned i);
402 { 402 {
403 //printf("ScopeDsymbol::emitMemberComments() %s\n", toChars()); 403 //printf("ScopeDsymbol::emitMemberComments() %s\n", toChars());
404 OutBuffer *buf = sc->docbuf; 404 OutBuffer *buf = sc->docbuf;
405 405
406 if (members) 406 if (members)
407 { char *m = "$(DDOC_MEMBERS \n"; 407 { const char *m = "$(DDOC_MEMBERS \n";
408 408
409 if (isModule()) 409 if (isModule())
410 m = "$(DDOC_MODULE_MEMBERS \n"; 410 m = "$(DDOC_MODULE_MEMBERS \n";
411 else if (isClassDeclaration()) 411 else if (isClassDeclaration())
412 m = "$(DDOC_CLASS_MEMBERS \n"; 412 m = "$(DDOC_CLASS_MEMBERS \n";
439 } 439 }
440 } 440 }
441 441
442 void emitProtection(OutBuffer *buf, PROT prot) 442 void emitProtection(OutBuffer *buf, PROT prot)
443 { 443 {
444 char *p; 444 const char *p;
445 445
446 switch (prot) 446 switch (prot)
447 { 447 {
448 case PROTpackage: p = "package"; break; 448 case PROTpackage: p = "package"; break;
449 case PROTprotected: p = "protected"; break; 449 case PROTprotected: p = "protected"; break;
916 } 916 }
917 917
918 DocComment *DocComment::parse(Scope *sc, Dsymbol *s, unsigned char *comment) 918 DocComment *DocComment::parse(Scope *sc, Dsymbol *s, unsigned char *comment)
919 { unsigned idlen; 919 { unsigned idlen;
920 920
921 //printf("parse(%s): '%s'\n", s->toChars(), comment);
921 if (sc->lastdc && isDitto(comment)) 922 if (sc->lastdc && isDitto(comment))
922 return NULL; 923 return NULL;
923 924
924 DocComment *dc = new DocComment(); 925 DocComment *dc = new DocComment();
925 if (!comment) 926 if (!comment)
961 unsigned idlen; 962 unsigned idlen;
962 963
963 unsigned char *name = NULL; 964 unsigned char *name = NULL;
964 unsigned namelen = 0; 965 unsigned namelen = 0;
965 966
967 //printf("parseSections('%s')\n", comment);
966 p = comment; 968 p = comment;
967 while (*p) 969 while (*p)
968 { 970 {
969 p = skipwhitespace(p); 971 p = skipwhitespace(p);
970 pstart = p; 972 pstart = p;
1086 1088
1087 void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf) 1089 void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
1088 { 1090 {
1089 if (namelen) 1091 if (namelen)
1090 { 1092 {
1091 static char *table[] = 1093 static const char *table[] =
1092 { "AUTHORS", "BUGS", "COPYRIGHT", "DATE", 1094 { "AUTHORS", "BUGS", "COPYRIGHT", "DATE",
1093 "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE", 1095 "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE",
1094 "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS", 1096 "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS",
1095 "VERSION" }; 1097 "VERSION" };
1096 1098
1430 /****************************************** 1432 /******************************************
1431 * Compare 0-terminated string with length terminated string. 1433 * Compare 0-terminated string with length terminated string.
1432 * Return < 0, ==0, > 0 1434 * Return < 0, ==0, > 0
1433 */ 1435 */
1434 1436
1435 int cmp(char *stringz, void *s, size_t slen) 1437 int cmp(const char *stringz, void *s, size_t slen)
1436 { 1438 {
1437 size_t len1 = strlen(stringz); 1439 size_t len1 = strlen(stringz);
1438 1440
1439 if (len1 != slen) 1441 if (len1 != slen)
1440 return len1 - slen; 1442 return len1 - slen;
1441 return memcmp(stringz, s, slen); 1443 return memcmp(stringz, s, slen);
1442 } 1444 }
1443 1445
1444 int icmp(char *stringz, void *s, size_t slen) 1446 int icmp(const char *stringz, void *s, size_t slen)
1445 { 1447 {
1446 size_t len1 = strlen(stringz); 1448 size_t len1 = strlen(stringz);
1447 1449
1448 if (len1 != slen) 1450 if (len1 != slen)
1449 return len1 - slen; 1451 return len1 - slen;
1576 /**************************************************** 1578 /****************************************************
1577 */ 1579 */
1578 1580
1579 int isKeyword(unsigned char *p, unsigned len) 1581 int isKeyword(unsigned char *p, unsigned len)
1580 { 1582 {
1581 static char *table[] = { "true", "false", "null" }; 1583 static const char *table[] = { "true", "false", "null" };
1582 1584
1583 for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) 1585 for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
1584 { 1586 {
1585 if (cmp(table[i], p, len) == 0) 1587 if (cmp(table[i], p, len) == 0)
1586 return 1; 1588 return 1;
1627 */ 1629 */
1628 1630
1629 void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) 1631 void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
1630 { 1632 {
1631 //printf("highlightText()\n"); 1633 //printf("highlightText()\n");
1632 char *sid = s->ident->toChars(); 1634 const char *sid = s->ident->toChars();
1633 FuncDeclaration *f = s->isFuncDeclaration(); 1635 FuncDeclaration *f = s->isFuncDeclaration();
1634 unsigned char *p; 1636 unsigned char *p;
1635 char *se; 1637 const char *se;
1636 1638
1637 int leadingBlank = 1; 1639 int leadingBlank = 1;
1638 int inCode = 0; 1640 int inCode = 0;
1639 int inComment = 0; // in <!-- ... --> comment 1641 int inComment = 0; // in <!-- ... --> comment
1640 unsigned iCodeStart; // start of code section 1642 unsigned iCodeStart; // start of code section
1876 FuncDeclaration *f = s->isFuncDeclaration(); 1878 FuncDeclaration *f = s->isFuncDeclaration();
1877 1879
1878 //printf("highlightCode(s = '%s', kind = %s)\n", sid, s->kind()); 1880 //printf("highlightCode(s = '%s', kind = %s)\n", sid, s->kind());
1879 for (unsigned i = offset; i < buf->offset; i++) 1881 for (unsigned i = offset; i < buf->offset; i++)
1880 { unsigned char c = buf->data[i]; 1882 { unsigned char c = buf->data[i];
1881 char *se; 1883 const char *se;
1882 1884
1883 se = Escape::escapeChar(c); 1885 se = Escape::escapeChar(c);
1884 if (se) 1886 if (se)
1885 { 1887 {
1886 size_t len = strlen(se); 1888 size_t len = strlen(se);
1918 */ 1920 */
1919 1921
1920 void highlightCode3(OutBuffer *buf, unsigned char *p, unsigned char *pend) 1922 void highlightCode3(OutBuffer *buf, unsigned char *p, unsigned char *pend)
1921 { 1923 {
1922 for (; p < pend; p++) 1924 for (; p < pend; p++)
1923 { char *s = Escape::escapeChar(*p); 1925 { const char *s = Escape::escapeChar(*p);
1924 if (s) 1926 if (s)
1925 buf->writestring(s); 1927 buf->writestring(s);
1926 else 1928 else
1927 buf->writeByte(*p); 1929 buf->writeByte(*p);
1928 } 1930 }
1940 unsigned errorsave = global.errors; 1942 unsigned errorsave = global.errors;
1941 Lexer lex(NULL, buf->data, 0, buf->offset - 1, 0, 1); 1943 Lexer lex(NULL, buf->data, 0, buf->offset - 1, 0, 1);
1942 Token tok; 1944 Token tok;
1943 OutBuffer res; 1945 OutBuffer res;
1944 unsigned char *lastp = buf->data; 1946 unsigned char *lastp = buf->data;
1945 char *highlight; 1947 const char *highlight;
1946 1948
1947 //printf("highlightCode2('%.*s')\n", buf->offset - 1, buf->data); 1949 //printf("highlightCode2('%.*s')\n", buf->offset - 1, buf->data);
1948 res.reserve(buf->offset); 1950 res.reserve(buf->offset);
1949 while (1) 1951 while (1)
1950 { 1952 {
2001 2003
2002 /*************************************** 2004 /***************************************
2003 * Find character string to replace c with. 2005 * Find character string to replace c with.
2004 */ 2006 */
2005 2007
2006 char *Escape::escapeChar(unsigned c) 2008 const char *Escape::escapeChar(unsigned c)
2007 { char *s; 2009 { const char *s;
2008 2010
2009 switch (c) 2011 switch (c)
2010 { 2012 {
2011 case '<': 2013 case '<':
2012 s = "&lt;"; 2014 s = "&lt;";