public override void ExitDeclarator(CParser.DeclaratorContext context) { if (context.gccDeclaratorExtension().Count > 0) { throw new SemanticException("gcc Declarator Extensions not supported"); } bool isPointer = context.pointer() != null; CParser.DirectDeclaratorContext directDecltor = context.directDeclarator(); if (directDecltor.Identifier() != null) { CDeclaration.PushIdentifierDeclarator(isPointer, directDecltor.GetText()); } else if (directDecltor.declarator() != null) { CDeclaration.NestedDeclarator(isPointer); } else if (directDecltor.GetText().EndsWith("*]")) { SematicError(context, "VLA not supported"); } else { if (directDecltor.directDeclarator().Identifier() != null) { CDeclaration.PushIdentifierDeclarator(false, directDecltor.directDeclarator().GetText()); } if (directDecltor.GetText().EndsWith(")")) { if (directDecltor.identifierList() != null) { SematicError(context, "old style (K&R) style functions not supported"); } else if (directDecltor.parameterTypeList() != null) { CDeclaration.EndFunctionDeclarator(isPointer, GetParameterListCount(directDecltor.parameterTypeList().parameterList())); } else { CDeclaration.EndFunctionDeclarator(isPointer, 0); } } else { bool hasAssgnExpr = directDecltor.assignmentExpression() != null; int numTypeQualifiers = GetTypeQualifierListCount(directDecltor.typeQualifierList()); CDeclaration.ArrayDeclarator(isPointer, numTypeQualifiers, hasAssgnExpr); } } }
//declarators public override void EnterDeclarator(CParser.DeclaratorContext context) { //beginFunctionDeclarator CParser.DirectDeclaratorContext directDecltor = context.directDeclarator(); if (directDecltor.GetText().EndsWith(")")) { if (directDecltor.identifierList() == null) { CDeclaration.BeginFunctionDeclarator(); } } }
public override void ExitDirectDeclarator([NotNull] CParser.DirectDeclaratorContext context) { var text = context.GetText(); var token = context.Start; // // directDeclarator is used for the routine name and individual parameters. Sometimes, a directDeclarator will be nested, if so then // we don't want this node // if (context.ChildCount == 1) { // // Determine if this is the routine name or a parameter name // if (in_params_list) { cur_parameter.param_name = text; Console.Write($" {text}"); // Parameter name } else { function_def.func_name = text; Console.WriteLine($"{text}"); // Routine name } } else { // // Look for an empty parameter list, e.g. bool rtn (); // if ((context.children [context.ChildCount - 1].GetText() == ")") && (context.children [context.ChildCount - 2].GetText() == "(")) { function_def.parameters.Clear(); Console.WriteLine("();\n"); } } } // End ExitDirectDeclarator