예제 #1
0
        public void CheckSemantic(LetExpresNode node, IScope scope = null)
        {
            foreach (var fieldInit in node.LocalOrFieldInits)
            {
                if (!TypeTable.IsDefinedType(fieldInit.TypeObj, out var type))
                {
                    Logger.LogError(fieldInit.Line, fieldInit.CharPositionInLine,
                                    $"The type '{fieldInit.TypeObj}' could not be found");
                    continue;
                }
                scope?.DefineSymbol(fieldInit.Symbol = new Symbol(fieldInit.Name, type));

                if (fieldInit.Initialization == null)
                {
                    fieldInit.ComputedType = fieldInit.Symbol.Type;
                    continue;
                }

                CheckSemantic(fieldInit.Initialization, scope);

                if ((CoolType)fieldInit.Initialization.ComputedType <= (CoolType)type)
                {
                    fieldInit.ComputedType = fieldInit.Initialization.ComputedType;
                }

                else
                {
                    Logger.LogError(fieldInit.Line, node.CharPositionInLine,
                                    $"Cannot implicity convert type '{fieldInit.ComputedType}' to '{type}'");
                }
            }
        }
예제 #2
0
 public void GenerateCode(LetExpresNode node, ICIL_CodeGenerator codeGenerator)
 {
     foreach (var field in node.LocalOrFieldInits)
     {
         GenerateCode(field, codeGenerator);
     }
 }