001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 the ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package eu.cqse.check.framework.preprocessor; 018 019import java.util.Optional; 020 021import org.conqat.engine.core.configuration.EFeatureToggle; 022 023import eu.cqse.check.framework.preprocessor.abap.AbapPreprocessor; 024import eu.cqse.check.framework.preprocessor.c.CPreprocessor; 025import eu.cqse.check.framework.preprocessor.c.EmptyMacroProvider; 026import eu.cqse.check.framework.preprocessor.c.new_c_preprocessor.NewCPreprocessor; 027import eu.cqse.check.framework.preprocessor.iec61131.Iec61131Preprocessor; 028import eu.cqse.check.framework.scanner.ELanguage; 029 030/** 031 * Factory for preprocessors. 032 */ 033public class PreprocessorFactory { 034 035 /** 036 * Creates a simple version of the preprocessor for the given language. This 037 * simple version can be used e.g. in tests that parse only one file. 038 * 039 * These simple preprocessors can especially not handle includes between files 040 * and other non-local language features. 041 */ 042 public static Optional<IPreprocessor> createLocalPreprocessor(ELanguage language) { 043 if (!PreprocessorUtils.hasPreprocessor(language)) { 044 // early return to ensure that new languages with preprocessor are added to the 045 // hasPreprocessor method 046 return Optional.empty(); 047 } 048 switch (language) { 049 case ABAP: 050 return Optional.of(new AbapPreprocessor()); 051 case CPP: 052 case OBJECTIVE_C: 053 if (EFeatureToggle.USE_NEW_PREPROCESSOR.isEnabled()) { 054 return Optional.of(new NewCPreprocessor(new EmptyMacroProvider(), true, true)); 055 } 056 return Optional.of(new CPreprocessor(new EmptyMacroProvider())); 057 case IEC61131: 058 return Optional.of(new Iec61131Preprocessor()); 059 default: 060 return Optional.empty(); 061 } 062 } 063}