AST.TupleLiteralExp CreateTupleLiteral(IToken rootToken, List <VariableDeclarationBag> vars) { if (TestNull(rootToken, vars)) { TupleType tupleTypeErr = new TupleType(TypesTable, new List <Property>()); TypesTable.RegisterType(tupleTypeErr); return(new AST.TupleLiteralExp(new Dictionary <string, AST.TupleLiteralPart>(), tupleTypeErr) .SetCodeSource(new CodeSource(rootToken))); } Dictionary <string, AST.TupleLiteralPart> parts = new Dictionary <string, AST.TupleLiteralPart>(); List <Property> tupleParts = new List <Property>(); foreach (var var in vars) { if (parts.ContainsKey(var.Name)) { Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, var.Name), rootToken, rootToken)); continue; } AST.OclExpression expr = var.Expression; if (var.Expression == null) { expr = new AST.ErrorExp(Library.Invalid); } Classifier type = var.Type; if (type == null) { type = expr.Type; } if (expr.Type.ConformsTo(type) == false) { Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_CreateTupleLiteral_Type_does_not_comform_to_declared_type)); } //hodnota var newProterty = new Property(var.Name, PropertyType.One, type); var newPart = new AST.TupleLiteralPart(newProterty, expr); parts.Add(var.Name, newPart); //typ tupleParts.Add(newProterty); } TupleType tupleType = new TupleType(TypesTable, tupleParts); TypesTable.RegisterType(tupleType); return(new AST.TupleLiteralExp(parts, tupleType) .SetCodeSource(new CodeSource(rootToken)));; }
AST.ClassLiteralExp CreateClassLiteral(IToken rootToken, List <VariableDeclarationBag> vars, List <IToken> tokenPath) { Classifier createdClass = ResolveTypePathName(tokenPath); if (createdClass == null || createdClass == Library.Invalid) { Errors.AddError(new CodeErrorItem(String.Format("Unable to create type '{0}'.", tokenPath.ConcatWithSeparator(@"::")), rootToken, rootToken)); } Dictionary <string, AST.TupleLiteralPart> parts = new Dictionary <string, AST.TupleLiteralPart>(); List <Property> classParts = new List <Property>(); foreach (var var in vars) { if (parts.ContainsKey(var.Name)) { Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, var.Name), rootToken, rootToken)); continue; } AST.OclExpression expr = var.Expression; if (var.Expression == null) { expr = new AST.ErrorExp(Library.Invalid); } Classifier type = var.Type; if (type == null) { type = expr.Type; } if (expr.Type.ConformsTo(type) == false) { Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_CreateTupleLiteral_Type_does_not_comform_to_declared_type)); } //hodnota var newProterty = new Property(var.Name, PropertyType.One, type); var newPart = new AST.TupleLiteralPart(newProterty, expr); parts.Add(var.Name, newPart); //typ classParts.Add(newProterty); } return(new AST.ClassLiteralExp(parts, createdClass) .SetCodeSource(new CodeSource(rootToken))); }
public string Visit(ErrorExp node) { sb.Append("ErrorExp"); return(string.Empty); }