diff options
Diffstat (limited to 'parser.fun')
-rw-r--r-- | parser.fun | 72 |
1 files changed, 34 insertions, 38 deletions
@@ -65,7 +65,7 @@ functor Parser(structure Tree: TREE; structure P: PPC; and evalRes = ER of word * ctype - and id = Lid of int | Gid of int * bool + and id = Lid of int | Gid of int and expr = Eid of int * id option | @@ -692,6 +692,11 @@ functor Parser(structure Tree: TREE; structure P: PPC; array_t _ => true | _ => false + fun elementType t = + case resolveType t of + array_t (_, elT) => elT + | _ => raise Unreachable + fun isStruct t = case resolveType t of struct_t _ => true @@ -1371,15 +1376,20 @@ functor Parser(structure Tree: TREE; structure P: PPC; ((eof, expr), ctx) end - and convAggr under t lvalue = + and convAggr under ea = + let + fun wrap t = EA (Eunop (UnopCast, ea), getPos ea, false, t) + val t = getT ea + in case under of UNone => ( - case t of - function_t _ => (pointer_t (1, t), false) - | array_t (_, el_t) => (pointer_t (1, el_t), false) - | _ => (t, lvalue) + case resolveType t of + function_t _ => wrap $ pointer_t (1, t) + | array_t (_, el_t) => wrap $ pointer_t (1, el_t) + | _ => ea ) - | _ => (t, lvalue) + | _ => ea + end and reduceVarToStack id = let @@ -1408,9 +1418,8 @@ functor Parser(structure Tree: TREE; structure P: PPC; reduceVarToStack lid else () - val (t, lvalue) = convAggr under t (not $ isFunc t) in - SOME (Lid lid, lvalue, t, NONE) + SOME $ convAggr under (EA (Eid (id, SOME $ Lid lid), pos, true, t)) end | NONE => findLocal scopes end @@ -1423,12 +1432,9 @@ functor Parser(structure Tree: TREE; structure P: PPC; in case res of SOME (GsDecl (_, _, t, _)) => - let - val (t', lvalue) = convAggr under t (not $ isFunc t) - in - (Gid (id, isFunc t), lvalue, t', NONE) - end - | SOME (GsEnumConst v) => (Gid (id, false), false, int_t, SOME v) + convAggr under (EA (Eid (id, SOME (Gid id)), pos, true, t)) + | SOME (GsEnumConst v) => + EA (Econst (id, Ninteger (Word.fromInt v)), pos, false, int_t) | SOME (GsTypedef _) => P.error pos `"type in place of an identifier" % | NONE => P.error pos `"unknown identifier" % @@ -1915,30 +1921,14 @@ functor Parser(structure Tree: TREE; structure P: PPC; end | checkMemberAccessByP _ _ = raise Unreachable - and checkStrlit under (EA (Estrlit id, pos, lvalue, t)) = - let - val (t, lvalue) = convAggr under t lvalue - in - EA (Estrlit id, pos, lvalue, t) - end - | checkStrlit _ _ = raise Unreachable - - and checkExpr ctx (under: under) (E as EA (e, pos, _, _)) = + and checkExpr ctx under (E as EA (e, pos, _, _)) = let val check = checkExpr ctx (* val () = printf `"Checking " A1 pea E `"\n" % *) in case e of - Eid (id', _) => - let - val (id, lvalue, t, const) = findId ctx pos under id' - in - case const of - SOME v => - EA (Econst (id', Ninteger (Word.fromInt v)), pos, false, int_t) - | _ => EA (Eid (id', SOME id), pos, lvalue, t) - end + Eid (id', _) => findId ctx pos under id' | EsizeofType _ => checkSizeofType E | EfuncCall _ => checkFuncCall (check UNone) E | Ebinop (_, _, _) => checkBinop (check UNone) E @@ -1947,7 +1937,7 @@ functor Parser(structure Tree: TREE; structure P: PPC; | EmemberByV _ => checkMemberAccessByV (check UNone) E | EmemberByP _ => checkMemberAccessByP (check UNone) E | Econst _ => E - | Estrlit _ => checkStrlit under E + | Estrlit _ => convAggr under E end and tryGetTypedefName (Ctx ctx) id = @@ -2966,8 +2956,6 @@ functor Parser(structure Tree: TREE; structure P: PPC; val (ini, ctx) = ctxWithLayer ctx' list parseCompoundInitializer val (tk, pos, ctx) = getTokenCtx ctx val status = oneOfEndTks tk terms - - val () = printf `"Status: " I status % in if status = 0 then dieExpTerms pos terms @@ -3249,7 +3237,15 @@ functor Parser(structure Tree: TREE; structure P: PPC; fun getCharArrayLen t = case resolveType t of - array_t (n, t) => if resolveType t = char_t then SOME n else NONE + array_t (n, t) => + let + val t = resolveType t + in + if t = char_t orelse t = uchar_t then + SOME n + else + NONE + end | _ => NONE fun convStrlitIni pos t ini = @@ -3737,7 +3733,7 @@ functor Parser(structure Tree: TREE; structure P: PPC; val (res, ctx) = parseDeclaration ctx val varInits = case res of - LocalVarInits l => l (* handleInis ctx l *) + LocalVarInits l => l | _ => raise Unreachable in collectDecls (List.revAppend (varInits, acc)) ctx |