1: 
  2: // Compiler implementation of the D programming language
  3: // Copyright (c) 1999-2011 by Digital Mars
  4: // All Rights Reserved
  5: // written by Walter Bright
  6: // http://www.digitalmars.com
  7: // License for redistribution is by either the Artistic License
  8: // in artistic.txt, or the GNU General Public License in gnu.txt.
  9: // See the included readme.txt for details.
 10: 
 11: #include <stdio.h>
 12: #include <ctype.h>
 13: static char __file__[] = __FILE__;      /* for tassert.h                */
 14: #include        "tassert.h"
 15: 
 16: #include "mars.h"
 17: #include "mtype.h"
 18: #include "declaration.h"
 19: #include "expression.h"
 20: #include "template.h"
 21: 
 22: static void indent(int indent)
 23: {
 24:     int i;
 25: 
 26:     for (i = 0; i < indent; i++)
 27:         printf(" ");
 28: }
 29: 
 30: static char *type_print(Type *type)
 31: {
 32:     return type ? type->toChars() : (char *) "null";
 33: }
 34: 
 35: void dumpExpressions(int i, Expressions *exps)
 36: {
 37:     if (exps)
 38:     {
 39:         for (size_t j = 0; j < exps->dim; j++)
 40:         {   Expression *e = exps->tdata()[j];
 41:             indent(i);
 42:             printf("(\n");
 43:             e->dump(i + 2);
 44:             indent(i);
 45:             printf(")\n");
 46:         }
 47:     }
 48: }
 49: 
 50: void Expression::dump(int i)
 51: {
 52:     indent(i);
 53:     printf("%p %s type=%s\n", this, Token::toChars(op), type_print(type));
 54: }
 55: 
 56: void IntegerExp::dump(int i)
 57: {
 58:     indent(i);
 59:     printf("%p %jd type=%s\n", this, (intmax_t)value, type_print(type));
warning C6067: Parameter '3' in call to 'printf' must be the address of the string
warning C6271: Extra argument passed to 'printf': parameter '4' is not used by the format string
60: } 61: 62: void IdentifierExp::dump(int i) 63: { 64: indent(i); 65: printf("%p ident '%s' type=%s\n", this, ident->toChars(), type_print(type)); 66: } 67: 68: void DsymbolExp::dump(int i) 69: { 70: indent(i); 71: printf("%p %s type=%s\n", this, s->toChars(), type_print(type)); 72: } 73: 74: void VarExp::dump(int i) 75: { 76: indent(i); 77: printf("%p %s var=%s type=%s\n", this, Token::toChars(op), var->toChars(), type_print(type)); 78: } 79: 80: void UnaExp::dump(int i) 81: { 82: indent(i); 83: printf("%p %s type=%s e1=%p\n", this, Token::toChars(op), type_print(type), e1); 84: if (e1) 85: e1->dump(i + 2); 86: } 87: 88: void CallExp::dump(int i) 89: { 90: UnaExp::dump(i); 91: dumpExpressions(i, arguments); 92: } 93: 94: void SliceExp::dump(int i) 95: { 96: indent(i); 97: printf("%p %s type=%s e1=%p\n", this, Token::toChars(op), type_print(type), e1); 98: if (e1) 99: e1->dump(i + 2); 100: if (lwr) 101: lwr->dump(i + 2); 102: if (upr) 103: upr->dump(i + 2); 104: } 105: 106: void DotIdExp::dump(int i) 107: { 108: indent(i); 109: printf("%p %s type=%s ident=%s e1=%p\n", this, Token::toChars(op), type_print(type), ident->toChars(), e1); 110: if (e1) 111: e1->dump(i + 2); 112: } 113: 114: void DotVarExp::dump(int i) 115: { 116: indent(i); 117: printf("%p %s type=%s var='%s' e1=%p\n", this, Token::toChars(op), type_print(type), var->toChars(), e1); 118: if (e1) 119: e1->dump(i + 2); 120: } 121: 122: void DotTemplateInstanceExp::dump(int i) 123: { 124: indent(i); 125: printf("%p %s type=%s ti='%s' e1=%p\n", this, Token::toChars(op), type_print(type), ti->toChars(), e1); 126: if (e1) 127: e1->dump(i + 2); 128: } 129: 130: void DelegateExp::dump(int i) 131: { 132: indent(i); 133: printf("%p %s func=%s type=%s e1=%p\n", this, Token::toChars(op), func->toChars(), type_print(type), e1); 134: if (e1) 135: e1->dump(i + 2); 136: } 137: 138: void BinExp::dump(int i) 139: { 140: indent(i); 141: const char *sop = Token::toChars(op); 142: if (op == TOKblit) 143: sop = "blit"; 144: else if (op == TOKconstruct) 145: sop = "construct"; 146: printf("%p %s type=%s e1=%p e2=%p\n", this, sop, type_print(type), e1, e2); 147: if (e1) 148: e1->dump(i + 2); 149: if (e2) 150: e2->dump(i + 2); 151: } 152: 153: 154: