Changeset 213
- Timestamp:
- 10/14/09 17:09:50 (2 years ago)
- Files:
-
- trunk/src/mtype.c (modified) (1 diff)
- trunk/src/mtype.h (modified) (1 diff)
- trunk/src/parse.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/mtype.c
r202 r213 6848 6848 } 6849 6849 else 6850 6850 { 6851 6851 Ldefault: 6852 6852 Type::resolve(loc, sc, pe, pt, ps); 6853 6853 } 6854 6854 } 6855 6855 6856 6856 void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 6857 6857 { 6858 6858 if (mod != this->mod) 6859 6859 { toCBuffer3(buf, hgs, mod); 6860 6860 return; 6861 6861 } 6862 6862 next->toCBuffer2(buf, hgs, this->mod); 6863 6863 6864 6864 buf->printf("[%s .. ", lwr->toChars()); 6865 6865 buf->printf("%s]", upr->toChars()); 6866 6866 } 6867 6867 6868 /***************************** TypeNewArray *****************************/ 6869 6870 /* T[new] 6871 */ 6872 6873 TypeNewArray::TypeNewArray(Type *next) 6874 : TypeNext(Tnarray, next) 6875 { 6876 //printf("TypeNewArray\n"); 6877 } 6878 6879 void TypeNewArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 6880 { 6881 if (mod != this->mod) 6882 { toCBuffer3(buf, hgs, mod); 6883 return; 6884 } 6885 next->toCBuffer2(buf, hgs, this->mod); 6886 buf->writestring("[new]"); 6887 } 6888 6868 6889 /***************************** Argument *****************************/ 6869 6890 6870 6891 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg) 6871 6892 { 6872 6893 this->type = type; 6873 6894 this->ident = ident; 6874 6895 this->storageClass = storageClass; 6875 6896 this->defaultArg = defaultArg; 6876 6897 } 6877 6898 6878 6899 Argument *Argument::syntaxCopy() 6879 6900 { 6880 6901 Argument *a = new Argument(storageClass, 6881 6902 type ? type->syntaxCopy() : NULL, 6882 6903 ident, 6883 6904 defaultArg ? defaultArg->syntaxCopy() : NULL); 6884 6905 return a; 6885 6906 } 6886 6907 6887 6908 Arguments *Argument::arraySyntaxCopy(Arguments *args) trunk/src/mtype.h
r199 r213 781 781 int equals(Object *o); 782 782 Type *reliesOnTident(); 783 783 void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod); 784 784 void toDecoBuffer(OutBuffer *buf, int flag); 785 785 Expression *getProperty(Loc loc, Identifier *ident); 786 786 TypeInfoDeclaration *getTypeInfoDeclaration(); 787 787 }; 788 788 789 789 struct TypeSlice : TypeNext 790 790 { 791 791 Expression *lwr; 792 792 Expression *upr; 793 793 794 794 TypeSlice(Type *next, Expression *lwr, Expression *upr); 795 795 Type *syntaxCopy(); 796 796 Type *semantic(Loc loc, Scope *sc); 797 797 void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps); 798 798 void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod); 799 799 }; 800 800 801 struct TypeNewArray : TypeNext 802 { 803 TypeNewArray(Type *next); 804 void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod); 805 }; 806 801 807 /**************************************************************/ 802 808 803 809 //enum InOut { None, In, Out, InOut, Lazy }; 804 810 805 811 struct Argument : Object 806 812 { 807 813 //enum InOut inout; 808 814 unsigned storageClass; 809 815 Type *type; 810 816 Identifier *ident; 811 817 Expression *defaultArg; 812 818 813 819 Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg); 814 820 Argument *syntaxCopy(); 815 821 Type *isLazyArray(); 816 822 void toDecoBuffer(OutBuffer *buf); 817 823 static Arguments *arraySyntaxCopy(Arguments *args); 818 824 static char *argsTypesToChars(Arguments *args, int varargs); 819 825 static void argsCppMangle(OutBuffer *buf, CppMangleState *cms, Arguments *arguments, int varargs); 820 826 static void argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Arguments *arguments, int varargs); trunk/src/parse.c
r208 r213 2206 2206 //printf("parseBasicType2()\n"); 2207 2207 while (1) 2208 2208 { 2209 2209 switch (token.value) 2210 2210 { 2211 2211 case TOKmul: 2212 2212 t = new TypePointer(t); 2213 2213 nextToken(); 2214 2214 continue; 2215 2215 2216 2216 case TOKlbracket: 2217 2217 // Handle []. Make sure things like 2218 2218 // int[3][1] a; 2219 2219 // is (array[1] of array[3] of int) 2220 2220 nextToken(); 2221 2221 if (token.value == TOKrbracket) 2222 2222 { 2223 2223 t = new TypeDArray(t); // [] 2224 2224 nextToken(); 2225 2225 } 2226 else if (token.value == TOKnew && peekNext() == TOKrbracket) 2227 { 2228 t = new TypeNewArray(t); // [new] 2229 nextToken(); 2230 nextToken(); 2231 } 2226 2232 else if (isDeclaration(&token, 0, TOKrbracket, NULL)) 2227 2233 { // It's an associative array declaration 2228 2234 2229 2235 //printf("it's an associative array\n"); 2230 2236 Type *index = parseType(); // [ type ] 2231 2237 t = new TypeAArray(t, index); 2232 2238 check(TOKrbracket); 2233 2239 } 2234 2240 else 2235 2241 { 2236 2242 //printf("it's type[expression]\n"); 2237 2243 inBrackets++; 2238 2244 Expression *e = parseExpression(); // [ expression ] 2239 2245 if (token.value == TOKslice) 2240 2246 { 2241 2247 nextToken(); 2242 2248 Expression *e2 = parseExpression(); // [ exp .. exp ] 2243 2249 t = new TypeSlice(t, e, e2); 2244 2250 } 2245 2251 else … … 2326 2332 } 2327 2333 2328 2334 // parse DeclaratorSuffixes 2329 2335 while (1) 2330 2336 { 2331 2337 switch (token.value) 2332 2338 { 2333 2339 #if CARRAYDECL 2334 2340 /* Support C style array syntax: 2335 2341 * int ident[] 2336 2342 * as opposed to D-style: 2337 2343 * int[] ident 2338 2344 */ 2339 2345 case TOKlbracket: 2340 2346 { // This is the old C-style post [] syntax. 2341 2347 TypeNext *ta; 2342 2348 nextToken(); 2343 2349 if (token.value == TOKrbracket) 2344 2350 { // It's a dynamic array 2345 2351 ta = new TypeDArray(t); // [] 2352 nextToken(); 2353 } 2354 else if (token.value == TOKnew && peekNext() == TOKrbracket) 2355 { 2356 t = new TypeNewArray(t); // [new] 2357 nextToken(); 2346 2358 nextToken(); 2347 2359 } 2348 2360 else if (isDeclaration(&token, 0, TOKrbracket, NULL)) 2349 2361 { // It's an associative array 2350 2362 2351 2363 //printf("it's an associative array\n"); 2352 2364 Type *index = parseType(); // [ type ] 2353 2365 check(TOKrbracket); 2354 2366 ta = new TypeAArray(t, index); 2355 2367 } 2356 2368 else 2357 2369 { 2358 2370 //printf("It's a static array\n"); 2359 2371 Expression *e = parseExpression(); // [ expression ] 2360 2372 ta = new TypeSArray(t, e); 2361 2373 check(TOKrbracket); 2362 2374 } 2363 2375 2364 2376 /* Insert ta into 2365 2377 * ts -> ... -> t … … 4248 4260 4249 4261 //printf("Parser::isDeclarator()\n"); 4250 4262 //t->print(); 4251 4263 if (t->value == TOKassign) 4252 4264 return FALSE; 4253 4265 4254 4266 while (1) 4255 4267 { 4256 4268 parens = FALSE; 4257 4269 switch (t->value) 4258 4270 { 4259 4271 case TOKmul: 4260 4272 //case TOKand: 4261 4273 t = peek(t); 4262 4274 continue; 4263 4275 4264 4276 case TOKlbracket: 4265 4277 t = peek(t); 4266 4278 if (t->value == TOKrbracket) 4267 4279 { 4280 t = peek(t); 4281 } 4282 else if (t->value == TOKnew && peek(t)->value == TOKrbracket) 4283 { 4284 t = peek(t); 4268 4285 t = peek(t); 4269 4286 } 4270 4287 else if (isDeclaration(t, 0, TOKrbracket, &t)) 4271 4288 { // It's an associative array declaration 4272 4289 t = peek(t); 4273 4290 } 4274 4291 else 4275 4292 { 4276 4293 // [ expression ] 4277 4294 // [ expression .. expression ] 4278 4295 if (!isExpression(&t)) 4279 4296 return FALSE; 4280 4297 if (t->value == TOKslice) 4281 4298 { t = peek(t); 4282 4299 if (!isExpression(&t)) 4283 4300 return FALSE; 4284 4301 } 4285 4302 if (t->value != TOKrbracket) 4286 4303 return FALSE; 4287 4304 t = peek(t);
