private void VisitNode(Literal node) { var desc = new LiteralTypeDescriptor { Value = node.Lit }; node.TypeDescriptor = desc; }
private TypeDescriptor GetAssignmentDesc(TypeDescriptor name, TypeDescriptor exp) { // assign integer value int valueInt = 0; // TODO: setting to 0 is not a good solution // fails if type check is not accurate NumberTypeDescriptor expNum = exp as NumberTypeDescriptor; PrimitiveTypeIntDescriptor expInt = exp as PrimitiveTypeIntDescriptor; if (expNum != null || expInt != null) { if (expNum != null) { valueInt = expNum.Num; } if (expInt != null) { valueInt = expInt.Value; } NumberTypeDescriptor nameNum = name as NumberTypeDescriptor; PrimitiveTypeIntDescriptor nameInt = name as PrimitiveTypeIntDescriptor; if (nameNum != null) { nameNum.Num = valueInt; return(nameNum); } if (nameInt != null) { nameInt.Value = valueInt; return(nameInt); } } // assign bool value PrimitiveTypeBooleanDescriptor expBoolean = exp as PrimitiveTypeBooleanDescriptor; PrimitiveTypeBooleanDescriptor nameBoolean = name as PrimitiveTypeBooleanDescriptor; if (expBoolean != null && nameBoolean != null) { nameBoolean.Value = expBoolean.Value; return(nameBoolean); } // assign string value LiteralTypeDescriptor expLiteral = exp as LiteralTypeDescriptor; LiteralTypeDescriptor nameLiteral = name as LiteralTypeDescriptor; if (expLiteral != null && nameLiteral != null) { nameLiteral.Value = expLiteral.Value; return(nameLiteral); } // assign an error if value unassignable return(new ErrorDescriptor("Assignment of value from " + exp.GetType().Name + " to " + name.GetType().Name + " failed")); }
private string GetIlType(TypeDescriptor desc, AbstractNode typeSpec) { // either the return type is a primitive (can get from the signature) PrimitiveTypeIntDescriptor intDesc = desc as PrimitiveTypeIntDescriptor; NumberTypeDescriptor numDesc = desc as NumberTypeDescriptor; if (intDesc != null || numDesc != null) { return("int32"); } PrimitiveTypeStringDescriptor stringDesc = desc as PrimitiveTypeStringDescriptor; LiteralTypeDescriptor litDesc = desc as LiteralTypeDescriptor; if (stringDesc != null || litDesc != null) { return("string"); } PrimitiveTypeBooleanDescriptor boolDesc = desc as PrimitiveTypeBooleanDescriptor; if (boolDesc != null) { return("bool"); } PrimitiveTypeVoidDescriptor voidDesc = desc as PrimitiveTypeVoidDescriptor; if (voidDesc != null) { return("void"); } // or it is a qualified name (can extract from the node) QualifiedName qName = typeSpec as QualifiedName; if (qName != null) { return(qName.GetStringName()); } // or it is an error ErrorDescriptor err = desc as ErrorDescriptor; if (err != null) { return(err.Message); } return(""); }
private string GetIlType(TypeDescriptor desc) { // either the return type is a primitive (can get from the signature) PrimitiveTypeIntDescriptor intDesc = desc as PrimitiveTypeIntDescriptor; NumberTypeDescriptor numDesc = desc as NumberTypeDescriptor; if (intDesc != null || numDesc != null) { return("int32"); } PrimitiveTypeStringDescriptor stringDesc = desc as PrimitiveTypeStringDescriptor; LiteralTypeDescriptor litDesc = desc as LiteralTypeDescriptor; if (stringDesc != null || litDesc != null) { return("string"); } PrimitiveTypeBooleanDescriptor boolDesc = desc as PrimitiveTypeBooleanDescriptor; if (boolDesc != null) { return("bool"); } PrimitiveTypeVoidDescriptor voidDesc = desc as PrimitiveTypeVoidDescriptor; if (voidDesc != null) { return("void"); } // or it is an error ErrorDescriptor err = desc as ErrorDescriptor; if (err != null) { return(err.Message); } return(""); }
private void PrintValue(AbstractNode node) { if (node.TypeDescriptor != null) { Console.ForegroundColor = ConsoleColor.DarkMagenta; NumberTypeDescriptor num = node.TypeDescriptor as NumberTypeDescriptor; if (num != null) { Console.Write(" " + num.Num); return; } PrimitiveTypeIntDescriptor primInt = node.TypeDescriptor as PrimitiveTypeIntDescriptor; if (primInt != null) { Console.Write(" " + primInt.Value); return; } PrimitiveTypeBooleanDescriptor primBool = node.TypeDescriptor as PrimitiveTypeBooleanDescriptor; if (primBool != null) { Console.Write(" " + primBool.Value); return; } LiteralTypeDescriptor lit = node.TypeDescriptor as LiteralTypeDescriptor; if (lit != null) { Console.Write(" " + lit.Value); return; } Console.ResetColor(); } }
public Literal(string literal) { Lit = literal; TypeDescriptor = new LiteralTypeDescriptor(literal); }