public Stmt VisitDeclarationStatement(Stmt.VariableDeclaration statement) { var function = LLVM.GetBasicBlockParent(LLVM.GetInsertBlock(_builder)); var type = statement.TypeSpecifier; var name = statement.Identifier.Source; if (_namedValues.ContainsKey(name)) { throw new Exception("Variable name already declared"); } LLVMValueRef alloca; if (type.Dimensions == 0) { alloca = EntryAllocation(function, type, name); } else { Expr.ArrayInitializer init = (Expr.ArrayInitializer)statement.Initializer; alloca = AllocateArray(function, type, name, init.DimensionSizes); } _namedValues.Add(name, new LLVMSymbol { Binding = statement.Binding, IsDecayed = false, KtsType = type, Value = alloca }); if (statement.Initializer == null) { if (type.Dimensions == 0) { if (type.IsFloat()) { LLVM.BuildStore(_builder, LLVM.ConstReal(LLVMPrimitiveType(type.Type), 0), alloca); } else { LLVM.BuildStore(_builder, LLVM.ConstInt(LLVMPrimitiveType(type.Type), 0, _lFalse), alloca); } } else { throw new Exception("Uninitialized array"); } } else { if (type.Dimensions == 0) { var initType = Visit(statement.Initializer); var initValue = _valueStack.Pop(); var casted = CheckedCast(initValue, initType, type); LLVM.BuildStore(_builder, casted, alloca); } } return(null); }
public TypeSpecifier VisitArrayInitializer(Expr.ArrayInitializer exp) { throw new NotImplementedException(); }
public T VisitArrayInitializer(Expr.ArrayInitializer exp);