Beispiel #1
0
        public ParseResult CheckManifestFieldKindAndDefinition(string taskName, string eventName, string fieldName, Field.Kind expectedFieldKind, int columnPos)
        {
            // by-passing check in case semantic validadation against manifest files is disabled
            if (!this.manifestSemanticsCheckEnabled)
            {
                return(new ParseResult(ParseCode.Success));
            }

            FieldDefinition fieldDef;

            if (!this.manifestLookup.TryGetField(taskName, eventName, fieldName, out fieldDef))
            {
                return(new ParseResult(
                           ParseCode.SemanticsUndefinedEventInManifest,
                           string.Format("The specified field ({0}) is not available for the event defined by the pair (TaskName: {1}, EventName: {2})", fieldName, taskName, eventName),
                           columnPos));
            }

            // check whether field matches the expected type
            Field.Kind fieldKind = SemanticsAnalyzer.GetAggregationFieldKind(fieldDef);
            if (fieldKind != expectedFieldKind)
            {
                return(new ParseResult(
                           ParseCode.SemanticsInvalidFieldKind,
                           string.Format("The specified field ({0}) is of type ({1}) but was defined as a ({2}) type", fieldName, fieldKind.ToString(), expectedFieldKind.ToString()),
                           columnPos));
            }

            return(new ParseResult(ParseCode.Success));
        }
Beispiel #2
0
        // this method implements the H production for the grammar
        // H -> identifier I
        private ParseResult H(Field.Kind fieldKind, TraceAggregationConfig telConfigEntry, ref List <Token> identifierList)
        {
            // check for argument name first
            Token token = this.lexAnalyzer.GetCurrentToken();

            if (token.Id != TokenId.Identifier)
            {
                return(new ParseResult(ParseCode.ErrorUnexpectedToken, "Expected field name", this.lexAnalyzer.Position));
            }

            // checking semantics against manifest file
            ParseResult parseRes = this.semanticsAnalyzer.CheckManifestFieldKindAndDefinition(telConfigEntry.TaskName, telConfigEntry.EventName, token.Text, fieldKind, this.lexAnalyzer.Position);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            // consume the argument name token
            this.lexAnalyzer.ConsumeToken();

            identifierList.Add(token);

            // try finding more aggregation kinds
            return(this.I(fieldKind, telConfigEntry, ref identifierList));
        }
Beispiel #3
0
        // this method implements the D production for the grammar
        // D -> E F G
        private ParseResult D(Field.Kind fieldKind, ref TraceAggregationConfig telConfigEntry)
        {
            // try parsing E , i.e get the param names
            List <Token> fieldTokenList = new List <Token>();
            ParseResult  parseRes       = this.E(fieldKind, telConfigEntry, ref fieldTokenList);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            // get the field names
            List <Field> fieldParamList;

            parseRes = SemanticsAnalyzer.CreateFieldsFromTokenList(fieldTokenList, fieldKind, out fieldParamList);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            // try parsing F , i.e get the aggregation kinds
            List <Token> aggregationParamList = new List <Token>();

            parseRes = this.F(ref aggregationParamList);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            // check if the aggregation kinds are valid
            List <Aggregation.Kinds> aggregationKindsList;

            parseRes = SemanticsAnalyzer.CreateAggregationKindsFromTokenList(aggregationParamList, fieldKind, out aggregationKindsList);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            // sucessfully parsed the aggregation entry E F
            // setting the current aggregation entry
            telConfigEntry.AddAggregationEntries(fieldParamList, aggregationKindsList);

            // try to find a new aggregation G
            parseRes = this.G(ref telConfigEntry);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            return(new ParseResult(ParseCode.Success));
        }
Beispiel #4
0
        // this method implements the I production for the grammar
        // I -> , H | \epsilon
        private ParseResult I(Field.Kind fieldKind, TraceAggregationConfig telConfigEntry, ref List <Token> identifierList)
        {
            // check for , first
            Token token = this.lexAnalyzer.GetCurrentToken();

            // \epsilon case
            if (token.Id != TokenId.Comma)
            {
                return(new ParseResult(ParseCode.Success, string.Empty, this.lexAnalyzer.Position));
            }

            // consume the , token
            this.lexAnalyzer.ConsumeToken();

            return(this.H(fieldKind, telConfigEntry, ref identifierList));
        }
Beispiel #5
0
        // this method implements the E production for the grammar
        // E -> ( H )
        private ParseResult E(Field.Kind fieldKind, TraceAggregationConfig telConfigEntry, ref List <Token> identifierList)
        {
            // check for ( first
            Token token = this.lexAnalyzer.GetCurrentToken();

            if (token.Id != TokenId.OpenParenthesis)
            {
                return(new ParseResult(ParseCode.ErrorUnexpectedToken, "Expected (", this.lexAnalyzer.Position));
            }

            // consume the ( token
            this.lexAnalyzer.ConsumeToken();

            // try parsing H , i.e get the param names
            List <string> fieldParamList = new List <string>();
            ParseResult   parseRes       = this.H(fieldKind, telConfigEntry, ref identifierList);

            if (parseRes.ParseCode != ParseCode.Success)
            {
                return(parseRes);
            }

            // A semantics check could be done here later against the trace manifest file

            // check for )
            token = this.lexAnalyzer.GetCurrentToken();

            if (token.Id != TokenId.CloseParenthesis)
            {
                return(new ParseResult(ParseCode.ErrorUnexpectedToken, "Expected )", this.lexAnalyzer.Position));
            }

            // consume the ) token
            this.lexAnalyzer.ConsumeToken();

            return(new ParseResult(ParseCode.Success));
        }
Beispiel #6
0
        // this method implements the B production for the grammar
        // A -> B | C
        private ParseResult A(ref TraceAggregationConfig telConfigEntry)
        {
            // check for "string" first
            Token token = this.lexAnalyzer.GetCurrentToken();

            if (token.Id != TokenId.Identifier)
            {
                return(new ParseResult(ParseCode.ErrorUnexpectedToken, "Identifier expected", this.lexAnalyzer.Position));
            }

            Field.Kind fieldKind = Field.CreateFieldKindFromName(token.Text);

            switch (fieldKind)
            {
            case Field.Kind.Property:
                return(this.B(ref telConfigEntry));

            case Field.Kind.Metric:
                return(this.C(ref telConfigEntry));

            default:
                return(new ParseResult(ParseCode.SemanticsInvalidFieldKind, "Invalid field kind specified - Expecting \"metric\" or \"property\"", this.lexAnalyzer.Position));
            }
        }
Beispiel #7
0
        public static ParseResult CreateFieldsFromTokenList(IEnumerable <Token> tokenList, Field.Kind fieldKind, out List <Field> paramList)
        {
            paramList = new List <Field>();

            foreach (var token in tokenList)
            {
                paramList.Add(new Field(token.Text, fieldKind));
            }

            return(new ParseResult(ParseCode.Success));
        }
Beispiel #8
0
        public static ParseResult CreateAggregationKindsFromTokenList(IEnumerable <Token> tokenList, Field.Kind fieldKind, out List <Aggregation.Kinds> aggregationTypes)
        {
            aggregationTypes = new List <Aggregation.Kinds>();

            foreach (var token in tokenList)
            {
                Aggregation.Kinds aggrType = Aggregation.Kinds.Undefined;

                // check whether the aggregation type name exists
                if (!SemanticsAnalyzer.CreateAggregationTypeFromName(token.Text, ref aggrType))
                {
                    return(new ParseResult(ParseCode.SemanticsInvalidAggregationType, "Invalid aggregation type", token.ColumnPos));
                }

                // check whether the aggregation type is supported by the field type
                if (!Field.IsAggregationAvailable(fieldKind, aggrType))
                {
                    return(new ParseResult(ParseCode.SemanticsInvalidAggregationType, "Invalid aggregation type for the requested field type", token.ColumnPos));
                }

                aggregationTypes.Add(aggrType);
            }

            return(new ParseResult(ParseCode.Success));
        }