/** Used by Template.Add() to Add args one by one w/o turning on full formal args definition signal */ public virtual void AddArgument(FormalArgument a) { if (FormalArguments == null) { FormalArguments = new List <FormalArgument>(); } a.Index = FormalArguments.Count; FormalArguments.Add(a); if (a.DefaultValueToken != null) { _numberOfArgsWithDefaultValues++; } }
/* * public static String getCardinalityName(int cardinality) { * switch (cardinality) { * case OPTIONAL : return "optional"; * case REQUIRED : return "exactly one"; * case ZERO_OR_MORE : return "zero-or-more"; * case ONE_OR_MORE : return "one-or-more"; * default : return "unknown"; * } * } */ public override bool Equals(object o) { if (o == null || !(o is FormalArgument)) { return(false); } FormalArgument other = (FormalArgument)o; if (!this.name.Equals(other.name)) { return(false); } // only check if there is a default value; that's all return(!((this.defaultValueToken != null && other.defaultValueToken == null) || (this.defaultValueToken == null && other.defaultValueToken != null))); }
public virtual void ReferenceAttribute(IToken templateToken, CommonTree id) { string name = id.Text; FormalArgument arg = impl.TryGetFormalArgument(name); if (arg != null) { int index = arg.Index; Emit1(id, Bytecode.INSTR_LOAD_LOCAL, index); } else { if (Interpreter.PredefinedAnonymousSubtemplateAttributes.Contains(name)) { errMgr.CompiletimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.Token); Emit(id, Bytecode.INSTR_NULL); } else { Emit1(id, Bytecode.INSTR_LOAD_ATTR, name); } } }
/** Used by Template.Add() to Add args one by one w/o turning on full formal args definition signal */ public virtual void AddArgument(FormalArgument a) { if (FormalArguments == null) FormalArguments = new List<FormalArgument>(); a.Index = FormalArguments.Count; FormalArguments.Add(a); if (a.DefaultValueToken != null) _numberOfArgsWithDefaultValues++; }
private object CreateGroupObject(BinaryReader reader, int key, Dictionary<int, object> objects) { var comparer = ObjectReferenceEqualityComparer<object>.Default; int typeKey = reader.ReadInt32(); if (typeKey == 0) { // this is a string return reader.ReadString(); } string typeName = (string)objects[typeKey]; if (typeName == typeof(bool).FullName) { return reader.ReadBoolean(); } else if (typeName == typeof(TemplateToken).FullName || typeName == typeof(CommonToken).FullName) { int channel = reader.ReadInt32(); int charPositionInLine = reader.ReadInt32(); int line = reader.ReadInt32(); int startIndex = reader.ReadInt32(); int stopIndex = reader.ReadInt32(); string text = reader.ReadString(); int tokenIndex = reader.ReadInt32(); int type = reader.ReadInt32(); CommonToken token = new CommonToken(type, text) { Channel = channel, CharPositionInLine = charPositionInLine, Line = line, StartIndex = startIndex, StopIndex = stopIndex, TokenIndex = tokenIndex, }; return token; } else if (typeName == typeof(CompiledTemplate).FullName) { CompiledTemplate compiledTemplate = new CompiledTemplate(); compiledTemplate.Name = reader.ReadString(); compiledTemplate.Prefix = reader.ReadString(); compiledTemplate.Template = reader.ReadString(); int templateDefStartTokenObject = reader.ReadInt32(); compiledTemplate.HasFormalArgs = reader.ReadBoolean(); int nativeGroupObject = reader.ReadInt32(); compiledTemplate.IsRegion = reader.ReadBoolean(); compiledTemplate.RegionDefType = (Template.RegionType)reader.ReadInt32(); compiledTemplate.IsAnonSubtemplate = reader.ReadBoolean(); int formalArgsLength = reader.ReadInt32(); if (formalArgsLength > 0) { for (int i = 0; i < formalArgsLength; i++) { int formalArgObject = reader.ReadInt32(); } } int stringsLength = reader.ReadInt32(); if (stringsLength >= 0) { compiledTemplate.strings = new string[stringsLength]; for (int i = 0; i < stringsLength; i++) compiledTemplate.strings[i] = reader.ReadString(); } int instrsLength = reader.ReadInt32(); if (instrsLength >= 0) compiledTemplate.instrs = reader.ReadBytes(instrsLength); compiledTemplate.codeSize = reader.ReadInt32(); int sourceMapLength = reader.ReadInt32(); if (sourceMapLength >= 0) { compiledTemplate.sourceMap = new Interval[sourceMapLength]; for (int i = 0; i < sourceMapLength; i++) { int start = reader.ReadInt32(); int length = reader.ReadInt32(); if (length >= 0) compiledTemplate.sourceMap[i] = new Interval(start, length); } } return compiledTemplate; } else if (typeName == typeof(FormalArgument).FullName) { string name = reader.ReadString(); int index = reader.ReadInt32(); IToken defaultValueToken = (IToken)objects[reader.ReadInt32()]; int defaultValueObject = reader.ReadInt32(); int compiledDefaultValue = reader.ReadInt32(); FormalArgument formalArgument = new FormalArgument(name, defaultValueToken); formalArgument.Index = index; return formalArgument; } else if (typeName == typeof(Template).FullName) { int implObject = reader.ReadInt32(); int localsCount = reader.ReadInt32(); for (int i = 0; i < localsCount; i++) { int localObject = reader.ReadInt32(); } int groupObject = reader.ReadInt32(); TemplateGroup group = this; Template template = new Template(group); return template; } else if (typeName == typeof(TemplateGroupFile).FullName) { bool isDefaultGroup = reader.ReadBoolean(); if (!isDefaultGroup) return this; else throw new NotSupportedException(); } else if (typeName == typeof(TemplateGroup).FullName) { bool isDefaultGroup = reader.ReadBoolean(); if (isDefaultGroup) return TemplateGroup.DefaultGroup; else throw new NotSupportedException(); } else { throw new NotImplementedException(); } }