230 typeSection, |
230 typeSection, |
231 funcDecl, |
231 funcDecl, |
232 operatorDecl |
232 operatorDecl |
233 ] |
233 ] |
234 where |
234 where |
|
235 |
|
236 fixInit v = concat $ map (\x -> case x of |
|
237 VarDeclaration a b (ids, t) c -> |
|
238 let typeId = (Identifier ((\(Identifier i _) -> i) (head ids) ++ "_tt") BTUnknown) in |
|
239 let res = [TypeDeclaration typeId t, VarDeclaration a b (ids, (SimpleType typeId)) c] in |
|
240 case t of |
|
241 RecordType _ _ -> res -- create a separated type declaration |
|
242 ArrayDecl _ _ -> res |
|
243 _ -> [x] |
|
244 _ -> error ("checkInit:\n" ++ (show v))) v |
|
245 |
235 varSection = do |
246 varSection = do |
236 try $ string "var" |
247 try $ string "var" |
237 comments |
248 comments |
238 v <- varsDecl1 True <?> "variable declaration" |
249 v <- varsDecl1 True <?> "variable declaration" |
239 comments |
250 comments |
240 return v |
251 return $ fixInit v |
241 |
252 |
242 constSection = do |
253 constSection = do |
243 try $ string "const" |
254 try $ string "const" |
244 comments |
255 comments |
245 c <- constsDecl <?> "const declaration" |
256 c <- constsDecl <?> "const declaration" |
246 comments |
257 comments |
247 return c |
258 return $ fixInit c |
248 |
259 |
249 typeSection = do |
260 typeSection = do |
250 try $ string "type" |
261 try $ string "type" |
251 comments |
262 comments |
252 t <- typesDecl <?> "type declaration" |
263 t <- typesDecl <?> "type declaration" |
293 else |
304 else |
294 return VoidType |
305 return VoidType |
295 char ';' |
306 char ';' |
296 comments |
307 comments |
297 forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
308 forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
298 inline <- liftM (any (== "inline;")) $ many functionDecorator |
309 decorators <- many functionDecorator |
|
310 let inline = any (== "inline;") decorators |
|
311 overload = any (== "overload;") decorators |
299 b <- if isImpl && (not forward) then |
312 b <- if isImpl && (not forward) then |
300 liftM Just functionBody |
313 liftM Just functionBody |
301 else |
314 else |
302 return Nothing |
315 return Nothing |
303 return $ [FunctionDeclaration i inline ret vs b] |
316 return $ [FunctionDeclaration i inline overload ret vs b] |
304 |
317 |
305 functionDecorator = do |
318 functionDecorator = do |
306 d <- choice [ |
319 d <- choice [ |
307 try $ string "inline;" |
320 try $ string "inline;" |
308 , try $ caseInsensitiveString "cdecl;" |
321 , try $ caseInsensitiveString "cdecl;" |
373 , try $ string "nil" >> return Null |
386 , try $ string "nil" >> return Null |
374 , reference >>= return . Reference |
387 , reference >>= return . Reference |
375 ] <?> "simple expression" |
388 ] <?> "simple expression" |
376 |
389 |
377 table = [ |
390 table = [ |
378 [ Prefix (try (string "not") >> return (PrefixOp "not")) |
391 [ Prefix (reservedOp pas "not">> return (PrefixOp "not")) |
379 , Prefix (try (char '-') >> return (PrefixOp "-"))] |
392 , Prefix (try (char '-') >> return (PrefixOp "-"))] |
380 , |
393 , |
381 [ Infix (char '*' >> return (BinOp "*")) AssocLeft |
394 [ Infix (char '*' >> return (BinOp "*")) AssocLeft |
382 , Infix (char '/' >> return (BinOp "/")) AssocLeft |
395 , Infix (char '/' >> return (BinOp "/")) AssocLeft |
383 , Infix (try (string "div") >> return (BinOp "div")) AssocLeft |
396 , Infix (try (string "div") >> return (BinOp "div")) AssocLeft |
384 , Infix (try (string "mod") >> return (BinOp "mod")) AssocLeft |
397 , Infix (try (string "mod") >> return (BinOp "mod")) AssocLeft |
385 , Infix (try (string "in") >> return (BinOp "in")) AssocNone |
398 , Infix (try (string "in") >> return (BinOp "in")) AssocNone |